home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 117 / PC Guia 117.iso / Software / Utils / Software6 / Product13 / googlebar-0.9.5.06-fx.xpi / chrome / googlebar.jar / content / googlebarOverlay.js < prev    next >
Text File  |  2005-02-21  |  123KB  |  3,543 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Googlebar for Mozilla.
  15.  *
  16.  * The Initial Developer of the Original Code is Andy Edmonds.
  17.  * Portions created by the Initial Developer are Copyright (C) 2001
  18.  * the Initial Developer. All Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *  Andy Boughton
  22.  *  Andrew Houghton
  23.  *  John Woods
  24.  *  Bernd Kuemmerlen     
  25.  *  Robert Mulcahy
  26.  *  Alfred Kayser
  27.  *  Reflex
  28.  *  Gary Turnbull
  29.  *  Raj Bhaskar
  30.  *  Joachim Thewes
  31.  *  Henrik Gemal
  32.  *  Robert Fernandes
  33.  *  Joe Chellman
  34.  *  Franki Cheung
  35.  *  Alban Fonrouge
  36.  *  Martin Hassman
  37.  *  Ufuk Kayserilioglu
  38.  *  Yoni Gilad 
  39.  *  Tim Schmidt
  40.  *  timeless
  41.  *  Francis Turner
  42.  *  
  43.  * Alternatively, the contents of this file may be used under the terms of
  44.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  45.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  46.  * in which case the provisions of the GPL or the LGPL are applicable instead
  47.  * of those above. If you wish to allow use of your version of this file only
  48.  * under the terms of either the GPL or the LGPL, and not to allow others to
  49.  * use your version of this file under the terms of the MPL, indicate your
  50.  * decision by deleting the provisions above and replace them with the notice
  51.  * and other provisions required by the GPL or the LGPL. If you do not delete
  52.  * the provisions above, a recipient may use your version of this file under
  53.  * the terms of any one of the MPL, the GPL or the LGPL.
  54.  *
  55.  * ***** END LICENSE BLOCK ***** */
  56.  
  57.  
  58. // ****************************
  59. // *  BEGIN NEWLY REFACTORED  *
  60. // ****************************
  61.  
  62.  
  63. // ****************************************
  64. // *  CONSTANTS - SERVICES, OBJECTS, ETC  *
  65. // ****************************************
  66.  
  67.  
  68. const GB_DRAG_SVC   = Components.classes["@mozilla.org/widget/dragservice;1"].getService(Components.interfaces.nsIDragService);
  69. const GB_PREF_SVC   = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  70. const GB_PROMPT_SVC = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  71. const GB_WINDOW_SVC = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  72.  
  73. const GB_FIND_OBJ = Components.classes['@mozilla.org/embedcomp/rangefind;1'].createInstance().QueryInterface(Components.interfaces.nsIFind);
  74. const GB_ROOT_OBJ = GB_PREF_SVC.getBranch(null);
  75. const GB_PREF_OBJ = GB_PREF_SVC.getBranch("googlebar.");
  76. const GB_URL_OBJ  = Components.classes["@mozilla.org/network/standard-url;1"].createInstance().QueryInterface(Components.interfaces.nsIURL);
  77.  
  78. try {
  79.     const GB_STRING_FLAG = "nsISupportsWString" in Components.interfaces && Components.interfaces.nsISupportsWString || "nsISupportsString" in Components.interfaces && Components.interfaces.nsISupportsString;
  80.     const GB_STRING_CONSTRUCTOR = Components.Constructor("@mozilla.org/supports-wstring;1" in Components.classes && Components.classes["@mozilla.org/supports-wstring;1"] || "@mozilla.org/supports-string;1" in Components.classes && Components.classes["@mozilla.org/supports-string;1"], GB_STRING_FLAG);
  81. }
  82. catch (e) {
  83.     myGooglebarUtil.logMessage("Problem creating string objects " + e);
  84. }
  85.  
  86.  
  87. // ******************************
  88. // *  LOCATION LISTENER OBJECT  *
  89. // ******************************
  90.  
  91.  
  92. var myGooglebarLocListener =
  93. {
  94.     QueryInterface: function(aIID) {
  95.         if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
  96.         aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
  97.         aIID.equals(Components.interfaces.nsISupports))
  98.         return this;
  99.         throw Components.results.NS_NOINTERFACE;
  100.     },
  101.  
  102.     onProgressChange: function (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {},
  103.     onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) {},
  104.     onSecurityChange: function(aWebProgress, aRequest, aState) {},
  105.     onLinkIconAvailable: function(a) {},
  106.     
  107.     onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus) {
  108.         if(aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP) {
  109.             if (myGooglebarHighlight.isHighlightOn()) {
  110.                 myGooglebarHighlight.highLightInPage("on");
  111.             }
  112.         }
  113.     },
  114.  
  115.     onLocationChange: function(aWebProgress, aRequest, aLocation) {
  116.         if (aLocation) {
  117.             var url = aLocation.spec;
  118.             var terms;
  119.     
  120.             // Old (broken) tests
  121.             //if(/^http:\/\/[^\.]*\.google\..*\/[^\?]*\?.*q=([^&]*)&.*/i.test(url))
  122.             //if(/^http:\/\/[^\.]*\.google\..*?\/[^\?]*?\?.*?q=([^&]*)/i.test(url))
  123.  
  124.             // Test to see if the URL matches the given pattern
  125.             if (/^http:\/\/[^\.]*?\.google\..*?\/[^\?]*?\?.*?q=([^&]*)&.*/i.test(url)) {
  126.                 terms = RegExp.$1;
  127.                 terms = terms.replace(/\+?(site|cache):[^\+]*\+?/g, "");
  128.                 terms = terms.replace(/\+/g, " ");
  129.                 terms = terms.replace(/\#.*$/g, "");
  130.                 terms = decodeURIComponent(terms);
  131.     
  132.                 var critBox = myGooglebarUtil.getElement("googlebarCriteria");
  133.                 critBox.value = terms;
  134.     
  135.                 googlebarCheckSearchbuttons();
  136.             }
  137.             else {
  138.               googlebarUpdateNewWindow();
  139.               googlebarCheckSearchbuttons();
  140.             }
  141.     
  142.             var siteBtn = myGooglebarUtil.getElement("site-separate");
  143.     
  144.             if (/^\s*http:\/\/[^\.]*\.google\..*\/.*/i.test(url)) {
  145.                 if (/^\s*http:\/\/[^\.]*\.google\..*\/[^\?]*\?.*q=site:([^&]*)(&.*)*/i.test(url)) {
  146.                     siteBtn.setAttribute("disabled", false);
  147.                 }
  148.                 else {
  149.                     siteBtn.setAttribute("disabled", true);
  150.                 }
  151.             }
  152.             else {
  153.                 siteBtn.setAttribute("disabled", false);
  154.             }
  155.     
  156.             // This block of code was put in to update the navigation list when location
  157.             // changes, even when not using the navigation items.  This may or may not
  158.             // be the desired behavior.  To remove this functionality the entire marked
  159.             // block of code can just simply be replaced with a single line:
  160.             //
  161.             //   googlebarLoadResults();
  162.             //
  163.             // That's it.
  164.     
  165.             // Begin Update Navigation Block
  166.             var inResult = false;
  167.             for (var i = 0; i < lastResults.length; i++) {
  168.                 if (url == lastResults[i]) {
  169.                     setTimeout("googlebarCheckNavigation(" + i + ")", 100);
  170.                     inResult = true;
  171.                     break;
  172.                 }
  173.             }
  174.             
  175.             if (!inResult) {
  176.                 googlebarLoadResults();
  177.             }
  178.             // End Update Navigation Block
  179.             
  180.             updateUp();
  181.         }
  182.     }
  183. };
  184.  
  185.  
  186. // ********************************
  187. // *  PREFERENCE OBSERVER OBJECT  *
  188. // ********************************
  189.  
  190.  
  191. var myGooglebarPrefObserver = {
  192.  
  193.     register: function() {
  194.         if (!GB_PREF_OBJ) {
  195.             return;
  196.         }
  197.     
  198.         var pbi = GB_PREF_OBJ.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
  199.         pbi.addObserver("", this, false);
  200.     },
  201.     
  202.     unregister: function() {
  203.         if (!GB_PREF_OBJ) {
  204.             return;
  205.         }
  206.         
  207.         var pbi = GB_PREF_OBJ.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
  208.         pbi.removeObserver("", this);
  209.     },
  210.     
  211.     observe: function(aSubject, aTopic, aData) {
  212.         // aSubject is the nsIPrefBranch being observed
  213.     
  214.         if (aTopic != "nsPref:changed") {
  215.             return;
  216.         }
  217.         
  218.         switch (aData) {
  219.             case "contextmenuoption":
  220.                 myGooglebarUtil.logMessage("contextmenuoption pref changed");
  221.                 break;
  222.                 
  223.             case "updateColors":
  224.                 myGooglebarUtil.logMessage("updateColors pref changed");
  225.                 break;
  226.                 
  227.             default:
  228.                 myGooglebarUtil.logMessage("unknown pref changed -- not paying attention to " + aData + " preference");
  229.                 break;
  230.         }
  231.     }
  232. };
  233.  
  234. myGooglebarPrefObserver.register();
  235.  
  236.  
  237. // ****************************
  238. // *  END NEWLY REFACTORED  *
  239. // ****************************
  240.  
  241.  
  242. var altAction, altCtrlAction, altShiftAction, ctrlAction, ctrlShiftAction, noneAction, shiftAction;
  243. var altLocation, altCtrlLocation, altShiftLocation, ctrlLocation, ctrlShiftLocation, noneLocation, shiftLocation;
  244.  
  245. var boolCritSelected, ggb_loaded, win, hkeytgl, srch4SelAppnd, googlebarRemoveNow;
  246. var loading = boolCritSelected = ggb_loaded = win = hkeytgl = srch4SelAppnd = googlebarRemoveNow = false;
  247. var openerUpdated = false;
  248.  
  249. var critIgnoreFocus = false;
  250. var critIgnoreClick = false;
  251. var populateUniv = false;
  252.  
  253. var n = 0;
  254. var term = '';
  255.  
  256. var arrDeckActs = [
  257.   "default", "site", "lucky", "groups", "directory", "images", "news",
  258.   "USA", "Catalog", "dictionary", "glossary", "mac", "bsd", "linux",
  259.   "microsoft", "webquotes", "viewer", "stocks", "froogle", "university", 
  260.   "nocalc", "gb-mycountry", "gb-mylocal", "gblogger", "scholar", "answers"
  261. ];
  262.  
  263. var arrDeckLocs = [
  264.   "Same Window", "New Tab", "New Window"
  265. ];
  266.  
  267. var cntrySfxs = new Array(99);
  268. var cntry2Srch, cntry2SrchIx;
  269.  
  270. var mycntrySfxs = new Array(69);
  271. var mycntry2Srch, mycntry2SrchIx;
  272.  
  273. var mylangSfxs = new Array(37);
  274. var mylang2Srch, mylang2SrchIx;
  275.  
  276. var cntryNewsSfxs = new Array(10);
  277. var cntryNews2Srch, cntryNews2SrchIx;
  278.  
  279. var cntryNewsSites = new Array(10);
  280. var cntryNewsSite;
  281.  
  282. var gbmycountryPref ;
  283.  
  284. var gbmylocalString = "";
  285. var gbmylocalPref = "";
  286.  
  287. // country domain override - for features like translate which need to use the USA site
  288. var onlyInUSA = "com";
  289.  
  290. // the option flags that we are going to save search history across browser sessions
  291. var autoSearchOption = false;
  292. var historyOption = true;
  293. var historyLoaded = false;
  294. var maxHistCnt;
  295. var sep = "||";
  296.  
  297. // the option value for how many results are listed from a search
  298. var resultLimit;
  299.  
  300. var autoSelectOption = true;
  301. var saveLastOption = false;
  302. var hideMenuOption = false;
  303. var queryStringOption = false;
  304. var sortByDate = false;
  305.  
  306. // hidden prefs should have a spot so here is the first one.
  307. var gbloggerStandardWinPref ;
  308.  
  309. // Remember the last focused element for stateful toggling
  310. var gStatefulPrevFocus = null;
  311.  
  312. // Array for storing last Google search results
  313. // (used by back/fwd result navigation stuff)
  314. var lastResultIndx = -99;
  315. var lastResults = new Array(0);
  316. var lastResultPages = new Array(0);
  317. var lastGoogle = null;
  318.  
  319. var university = null;
  320. var universityName = null;
  321.  
  322. ///////////////////////////////////////////////////////////////////////////////
  323. /////////////////////////////////// Init //////////////////////////////////////
  324.  
  325. function googlebarDisplayCheck()
  326. {
  327.     // make sure that we are loading the preferences
  328.     googlebarInitPrefs();
  329.  
  330.     if (!historyLoaded) {
  331.         historyLoaded = true;
  332.  
  333.         if (historyOption) {
  334.             googlebarInitHistory();
  335.         }
  336.         else {
  337.             GB_PREF_OBJ.setCharPref("history", "");
  338.         }
  339.     }
  340.  
  341.     myGooglebarHighlight.displayCheck();
  342.  
  343.     if (populateUniv) {
  344.         reallyUpdateUniv();
  345.     }
  346.  
  347.     googlebarLoadResults();
  348.     googlebarUpdateCriteriaDropmarker();
  349. }
  350.  
  351. function googlebarUpdateCriteriaDropmarker(inPrefs)
  352. {
  353.     if (inPrefs) {
  354.         historyOption = myGooglebarUtil.getElement("historyoption").checked;
  355.     }
  356.  
  357.     var critMenu = myGooglebarUtil.getElement("googlebarCriteria");
  358.  
  359.     if (!critMenu) {
  360.         alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.googlebarUpdateCriteriaDropmarker.1"));
  361.     }
  362.     else {
  363.         var critMenuDrop = myGooglebarUtil.getAnonymousElement(critMenu, "class", "menulist-dropmarker");
  364.         critMenuDrop.setAttribute("hidden", !historyOption);
  365.     }
  366.  
  367.     // clear the history when it was switched off
  368.     if (!historyOption) {
  369.       googlebarClearHistory( false ); // and clear the critBox
  370.     }
  371. }
  372.  
  373. function googlebarInitCustom()
  374. {
  375.     var customArray = new Array();
  376.     try {
  377.       var string = GB_PREF_OBJ.getComplexValue("customList", GB_STRING_FLAG).data;        
  378.       customArray = string.split(sep);
  379.       googlebarUpdateCustomList(customArray);
  380.     }
  381.     catch(e) {
  382.         myGooglebarUtil.logMessage("\Custom list init failure caught\n" + e);
  383.     }
  384. }
  385.  
  386. function googlebarInitHistory()
  387. {
  388.     var historyArray = new Array();
  389.     try {
  390.       var string = GB_PREF_OBJ.getComplexValue("history", GB_STRING_FLAG).data;        
  391.       historyArray = string.split(sep);
  392.     }
  393.     catch(e) {
  394.         myGooglebarUtil.logMessage("\nHistory init failure caught\n" + e);
  395.     }
  396.  
  397.     // iterate over the saved history items and add them to the list
  398.     // and make sure to use the second paramenter of the addToHistory
  399.     // function so that we don't add it to the saved preference again
  400.     for (var i = 0; i < historyArray.length; i++) {
  401.         if (historyArray[i]) {
  402.             googlebarAddToHistory(historyArray[i], true);
  403.         }
  404.     }
  405. }
  406.  
  407. function googlebarInitPrefs()
  408. {
  409.     // this is a leftover from the early days.
  410.     // We used to use a try googlebarReadPref and catch the missing pref failures
  411.     // here, and set them. Then the prefs grewup and they now have their own try
  412.     // catch blocks for each pref. The way it was done before was ok, for a few
  413.     // prefs. If you add a pref, the be sure to add it to both Firefox and Seamonkey
  414.     // user interfaces. googlebarPrefDialog.xul
  415.     googlebarReadPref();
  416. }
  417.  
  418. function googlebarReadPref() 
  419. {
  420.     /***********************************
  421.        Modifier Key Action Preferences
  422.      ***********************************/
  423.      
  424.     try { 
  425.         altAction = GB_PREF_OBJ.getCharPref("ActionAlt");
  426.     }
  427.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  428.         GB_PREF_OBJ.setCharPref("ActionAlt", "0");  // Default
  429.         altAction = GB_PREF_OBJ.getCharPref("ActionAlt");
  430.     }
  431.     
  432.     try {
  433.         altCtrlAction = GB_PREF_OBJ.getCharPref("ActionAltCtrl");
  434.     }
  435.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  436.         GB_PREF_OBJ.setCharPref("ActionAltCtrl", "0");  // Default
  437.         altCtrlAction = GB_PREF_OBJ.getCharPref("ActionAltCtrl");
  438.     }
  439.     
  440.     try {
  441.         altShiftAction = GB_PREF_OBJ.getCharPref("ActionAltShift");
  442.     }
  443.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  444.         GB_PREF_OBJ.setCharPref("ActionAltShift", "0");  // Default
  445.         altShiftAction = GB_PREF_OBJ.getCharPref("ActionAltShift");
  446.     }      
  447.     
  448.     try {
  449.         ctrlAction = GB_PREF_OBJ.getCharPref("ActionCtrl");
  450.     }
  451.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  452.         GB_PREF_OBJ.setCharPref("ActionCtrl", "0");  // Default
  453.         ctrlAction = GB_PREF_OBJ.getCharPref("ActionCtrl");
  454.     } 
  455.         
  456.     try {
  457.         ctrlShiftAction = GB_PREF_OBJ.getCharPref("ActionCtrlShift");
  458.     }
  459.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  460.         GB_PREF_OBJ.setCharPref("ActionCtrlShift", "0");  // Default
  461.         ctrlShiftAction = GB_PREF_OBJ.getCharPref("ActionCtrlShift");
  462.     }      
  463.         
  464.     try {
  465.         noneAction = GB_PREF_OBJ.getCharPref("ActionNone");
  466.     }
  467.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  468.         GB_PREF_OBJ.setCharPref("ActionNone", "0");  // Default
  469.         noneAction = GB_PREF_OBJ.getCharPref("ActionNone");
  470.     }        
  471.         
  472.     try {
  473.         shiftAction = GB_PREF_OBJ.getCharPref("ActionShift");
  474.     }
  475.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  476.         GB_PREF_OBJ.setCharPref("ActionShift", "0");  // Default
  477.         shiftAction = GB_PREF_OBJ.getCharPref("ActionShift");
  478.     }
  479.  
  480.     /*************************************
  481.        Modifier Key Location Preferences
  482.      *************************************/
  483.  
  484.     try {
  485.         altLocation = GB_PREF_OBJ.getCharPref("LocationAlt");
  486.     }
  487.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  488.         GB_PREF_OBJ.setCharPref("LocationAlt", "0");  // Same Window
  489.         altLocation = GB_PREF_OBJ.getCharPref("LocationAlt");
  490.     }
  491.  
  492.     try {
  493.         altCtrlLocation = GB_PREF_OBJ.getCharPref("LocationAltCtrl");
  494.     }
  495.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  496.         GB_PREF_OBJ.setCharPref("LocationAltCtrl", "0");  // Same Window
  497.         altCtrlLocation = GB_PREF_OBJ.getCharPref("LocationAltCtrl");
  498.     }
  499.  
  500.     try {
  501.         altShiftLocation = GB_PREF_OBJ.getCharPref("LocationAltShift");
  502.     }
  503.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  504.         GB_PREF_OBJ.setCharPref("LocationAltShift", "0");  // Same Window
  505.         altShiftLocation = GB_PREF_OBJ.getCharPref("LocationAltShift");
  506.     }
  507.    
  508.     try {
  509.         ctrlLocation = GB_PREF_OBJ.getCharPref("LocationCtrl");
  510.     }
  511.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  512.         GB_PREF_OBJ.setCharPref("LocationCtrl", "1");  // New Tab
  513.         ctrlLocation = GB_PREF_OBJ.getCharPref("LocationCtrl");
  514.     }
  515.  
  516.     try {
  517.         ctrlShiftLocation = GB_PREF_OBJ.getCharPref("LocationCtrlShift");
  518.     }
  519.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  520.         GB_PREF_OBJ.setCharPref("LocationCtrlShift", "1");  // New Tab
  521.         ctrlShiftLocation = GB_PREF_OBJ.getCharPref("LocationCtrlShift");
  522.     }
  523.  
  524.     try {
  525.         noneLocation = GB_PREF_OBJ.getCharPref("LocationNone");
  526.     }
  527.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  528.         GB_PREF_OBJ.setCharPref("LocationNone", "0");  // Same Window
  529.         noneLocation = GB_PREF_OBJ.getCharPref("LocationNone");
  530.     }
  531.     
  532.     try {
  533.         shiftLocation = GB_PREF_OBJ.getCharPref("LocationShift");
  534.     }
  535.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  536.         GB_PREF_OBJ.setCharPref("LocationShift", "2");  // New Window
  537.         shiftLocation = GB_PREF_OBJ.getCharPref("LocationShift");
  538.     }
  539.  
  540.     /****************************************
  541.        Domain Specific Preferences (Search)
  542.      ****************************************/
  543.  
  544.     try {
  545.         cntry2SrchIx = GB_PREF_OBJ.getIntPref("country2Search");
  546.     }
  547.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  548.         GB_PREF_OBJ.setIntPref("country2Search", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.country_default"));
  549.         cntry2SrchIx = GB_PREF_OBJ.getIntPref("country2Search");
  550.     }
  551.             
  552.     cntrySfxsInit();
  553.     cntry2Srch = cntrySfxs[cntry2SrchIx]; 
  554.  
  555.  
  556.     // &cr=countryUK
  557.     try {
  558.         mycntry2SrchIx = GB_PREF_OBJ.getIntPref("mycountry2Search");
  559.     }
  560.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  561.         GB_PREF_OBJ.setIntPref("mycountry2Search", 0 ); // cr=countryUS
  562.         mycntry2SrchIx = GB_PREF_OBJ.getIntPref("mycountry2Search");
  563.     }
  564.  
  565.     mycntrySfxsInit();
  566.     mycntry2Srch = mycntrySfxs[mycntry2SrchIx]; 
  567.  
  568.     // &lr=lang_en 
  569.     try {
  570.         mylang2SrchIx = GB_PREF_OBJ.getIntPref("mylang2Search");
  571.     }
  572.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  573.         GB_PREF_OBJ.setIntPref("mylang2Search", 0 ); // lr=en
  574.         mylang2SrchIx = GB_PREF_OBJ.getIntPref("mylang2Search");
  575.     }
  576.  
  577.     mylangSfxsInit();
  578.     mylang2Srch = mylangSfxs[mylang2SrchIx]; 
  579.  
  580.  
  581.     /**************************************
  582.        Domain Specific Preferences (News)
  583.      **************************************/
  584.  
  585.     try {
  586.         cntryNews2SrchIx = GB_PREF_OBJ.getIntPref("countryNews2Search");
  587.     }
  588.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  589.         GB_PREF_OBJ.setIntPref("countryNews2Search", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.news.country_default"));
  590.         cntryNews2SrchIx = GB_PREF_OBJ.getIntPref("countryNews2Search");
  591.     }
  592.             
  593.     cntryNewsSfxsInit();
  594.     cntryNews2Srch = cntryNewsSfxs[cntryNews2SrchIx];
  595.     cntryNewsSite = cntryNewsSites[cntryNews2SrchIx];
  596.     
  597.     /***********************************
  598.        Other Miscellaneous Preferences
  599.      ***********************************/
  600.  
  601.     try {
  602.         autoSearchOption = GB_PREF_OBJ.getBoolPref("autosearchoption");
  603.     }
  604.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  605.         GB_PREF_OBJ.setBoolPref("autosearchoption", false); // Auto Search When History Item Selected
  606.         autoSearchOption = GB_PREF_OBJ.getBoolPref("autosearchoption");
  607.     }
  608.  
  609.     try {
  610.         cntxtmnuopt = GB_PREF_OBJ.getBoolPref("contextmenuoption");
  611.     }
  612.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  613.         GB_PREF_OBJ.setBoolPref("contextmenuoption", true);
  614.         cntxtmnuopt = GB_PREF_OBJ.getBoolPref("contextmenuoption");
  615.     }
  616.  
  617.     try {
  618.         hideMenuOption = GB_PREF_OBJ.getBoolPref("hidemenuoption");
  619.     }
  620.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  621.         GB_PREF_OBJ.setBoolPref("hidemenuoption", false); // Hide Menu Items Promoted to Buttons
  622.         hideMenuOption = GB_PREF_OBJ.getBoolPref("hidemenuoption");
  623.     }
  624.  
  625.     try {
  626.         historyOption = GB_PREF_OBJ.getBoolPref("historyoption");
  627.     }
  628.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  629.         GB_PREF_OBJ.setBoolPref("historyoption", true); // Save History    
  630.         GB_PREF_OBJ.setCharPref("history", "googlebar"); // History Value 
  631.         historyOption = GB_PREF_OBJ.getBoolPref("historyoption");
  632.     }
  633.  
  634.     try {
  635.         hkeytgl = GB_PREF_OBJ.getBoolPref("hotkeySelectionToggles");
  636.     }
  637.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  638.         GB_PREF_OBJ.setBoolPref("hotkeySelectionToggles", false); // mimic ctrl-L or toggle
  639.         hkeytgl = GB_PREF_OBJ.getBoolPref("hotkeySelectionToggles");
  640.     }
  641.  
  642.     try {
  643.         srch4SelAppnd = GB_PREF_OBJ.getBoolPref("search4SelectedAppends");
  644.     }
  645.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  646.         GB_PREF_OBJ.setBoolPref("search4SelectedAppends", false); // replace or append text
  647.         srch4SelAppnd = GB_PREF_OBJ.getBoolPref("search4SelectedAppends");
  648.     }
  649. /*
  650.     try {
  651.         labsOption = GB_PREF_OBJ.getBoolPref("searchoption");
  652.     }
  653.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  654.         GB_PREF_OBJ.setBoolPref("searchoption", false); // Google Labs
  655.         labsOption = GB_PREF_OBJ.getBoolPref("searchoption");
  656.     }
  657. */
  658.     try {
  659.         maxHistCnt = GB_PREF_OBJ.getIntPref("maxHistCnt");
  660.     }
  661.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  662.         GB_PREF_OBJ.setIntPref("maxHistCnt", 10); // Maximum History Values Kept
  663.         maxHistCnt = GB_PREF_OBJ.getIntPref("maxHistCnt");
  664.     }
  665.  
  666.     try {
  667.         queryStringOption = GB_PREF_OBJ.getBoolPref("querystringoption");
  668.     }
  669.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  670.         GB_PREF_OBJ.setBoolPref("querystringoption", false); // Ignore Query String for Up Dir Button
  671.         queryStringOption = GB_PREF_OBJ.getBoolPref("querystringoption");
  672.     }
  673.  
  674.     try {
  675.         autoSelectOption = GB_PREF_OBJ.getBoolPref("autoselectoption");
  676.     }
  677.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  678.         GB_PREF_OBJ.setBoolPref("autoselectoption", true); // Auto Select Search Term Criteria
  679.         autoSelectOption = GB_PREF_OBJ.getBoolPref("autoselectoption");
  680.     }
  681.  
  682.     try {
  683.         saveLastOption = GB_PREF_OBJ.getBoolPref("savelastoption");
  684.     }
  685.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  686.         GB_PREF_OBJ.setBoolPref("savelastoption", false); // Save Last Search Type
  687.         saveLastOption = GB_PREF_OBJ.getBoolPref("savelastoption");
  688.     }
  689.  
  690.     try {
  691.         sortByDate = GB_PREF_OBJ.getBoolPref("sortByDate");
  692.     }
  693.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  694.         GB_PREF_OBJ.setBoolPref("sortByDate", false); // Sort Google Search Results by Date
  695.         sortByDate = GB_PREF_OBJ.getBoolPref("sortByDate");
  696.     }
  697.  
  698.     try {
  699.         resultLimit = GB_PREF_OBJ.getIntPref("resultLimit");
  700.     }
  701.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  702.         GB_PREF_OBJ.setIntPref("resultLimit", -1); // Number of Results to Return - Negative value ignored
  703.         resultLimit = GB_PREF_OBJ.getIntPref("resultLimit");
  704.     }
  705.  
  706.     // If there was a previous university selected
  707.     // then use that as the default, otherwise just
  708.     // ignore it
  709.     try {
  710.         university = GB_PREF_OBJ.getCharPref("university");
  711.         universityName = GB_PREF_OBJ.getCharPref("universityName");
  712.         setUniv(university, universityName);
  713.     }
  714.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  715.       GB_PREF_OBJ.setCharPref("university","");
  716.       GB_PREF_OBJ.setCharPref("universityName","");
  717.       university = GB_PREF_OBJ.getCharPref("university");
  718.       universityName = GB_PREF_OBJ.getCharPref("universityName");
  719.     }
  720.  
  721.     try {
  722.         var showLabels = GB_PREF_OBJ.getBoolPref("showLabels");
  723.     }
  724.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  725.         myGooglebarUtil.logMessage('Resetting label pref');
  726.         GB_PREF_OBJ.setBoolPref("showLabels", false); // Show Toolbar Button Labels
  727.     }
  728.  
  729.     myGooglebarUtil.getElement("LabelsButtonItem").setAttribute("checked", GB_PREF_OBJ.getBoolPref("showLabels"));
  730.     googlebarLabels();
  731.  
  732.     try {
  733.         var lockOrdinals = GB_PREF_OBJ.getBoolPref("lockOrdinals");
  734.     }
  735.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  736.         myGooglebarUtil.logMessage('Resetting ordinal pref');
  737.         GB_PREF_OBJ.setBoolPref("lockOrdinals", true); // Lock Toolbar Button Positions
  738.     }
  739.  
  740.     myGooglebarUtil.getElement("OrderLockButtonItem").setAttribute("checked", GB_PREF_OBJ.getBoolPref("lockOrdinals"));
  741.     googlebarOrdinals();
  742.  
  743.     /*************************************
  744.        Experimental Preferences
  745.      *************************************/
  746.  
  747.     try {
  748.         var googleSuggest = GB_PREF_OBJ.getBoolPref("googleSuggest");
  749.     }
  750.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  751.         myGooglebarUtil.logMessage('Resetting Google Suggest pref');
  752.         GB_PREF_OBJ.setBoolPref("googleSuggest", false); // Use Google Suggest
  753.     }
  754.  
  755.     try {
  756.         ggb_init();
  757.     }
  758.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  759.     }
  760.  
  761.     setGoogleContextMenu();
  762.     
  763.     if (myGooglebarUtil.isInFirefox()) {
  764.  
  765.         // workaround bug 6171
  766.         try {
  767.             historyOption = GB_PREF_OBJ.getBoolPref("historyoption");
  768.             maxHistCnt = GB_PREF_OBJ.getIntPref("maxHistCnt");
  769.             if(historyOption == "false") {
  770.                 GB_PREF_OBJ.setIntPref("maxHistCnt", 0);
  771.                 maxHistCnt = GB_PREF_OBJ.getIntPref("maxHistCnt");
  772.             }
  773.         }
  774.         catch(e) {
  775.             myGooglebarUtil.logMessage( e );
  776.         }
  777.         // end workaround bug 6171
  778.  
  779.     }
  780.  
  781.     myGooglebarUtil.logMessage("Finished ReadPrefs OK\n");
  782. }
  783.  
  784. function ggb_init()
  785. {
  786.     if (!ggb_loaded) {
  787.         window.removeEventListener("keypress",googlebarDisplayCheck,true);
  788.         window.removeEventListener("mousemove",googlebarDisplayCheck,true);
  789.  
  790.         ggb_loaded = true;
  791.  
  792.         if (!myGooglebarUtil.isInFirefox()){
  793.             check4NewInstall();
  794.         }
  795.  
  796.         window.getBrowser().addProgressListener(myGooglebarLocListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
  797.         window.getBrowser().addProgressListener(myGooglebarLocListener, Components.interfaces.nsIWebProgress.STATE_STOP);
  798.  
  799.         var hideExtras = !(myGooglebarUtil.getElement("extras-box").childNodes.length > 0);
  800.  
  801.         myGooglebarUtil.getElement("extras-box").setAttribute("hidden", hideExtras);
  802.         myGooglebarUtil.getElement("ExtrasButtonItem").setAttribute("hidden", hideExtras);
  803.  
  804.         myGooglebarUtil.getElement("LabelsButtonItem").addEventListener("DOMAttrModified", ggb_LabelListener, false);
  805.         myGooglebarUtil.getElement("OrderLockButtonItem").addEventListener("DOMAttrModified", ggb_OrdinalListener, false);
  806.  
  807.         if (myGooglebarUtil.isInFirefox()){
  808.             myGooglebarUtil.getElement("gb-prefill-separate").setAttribute("hidden", true);
  809.             myGooglebarUtil.getElement("gb-prefillButtonItem").setAttribute("hidden", true);
  810.         }
  811.         
  812.         googlebarSyncMenuButton("comp-menu", "lastCompSearch");
  813.         googlebarSyncMenuButton("cust-menu", "lastCustSearch");
  814.         googlebarSyncMenuButton("info-menu", "lastInfoSearch");
  815.         googlebarSyncMenuButton("spec-menu", "lastSpecSearch");
  816.  
  817.         googlebarGoPopupMenus();
  818.         initCustomOrder(); // this function is actually in googlebarDragAndDrop.js
  819.         googlebarInitCustom();
  820.  
  821.         // Try to put the hide/show menuitem under the toolbar popup
  822.         var toolbarContainer = myGooglebarUtil.getElement("menu_viewPopup");
  823.         var toolbarPopup;
  824.         if (toolbarContainer != null)
  825.         {
  826.             for (var i = 0; i < toolbarContainer.childNodes.length; i++) {
  827.                 if ( toolbarContainer.childNodes.item(i).nodeName == "menu"
  828.                     && toolbarContainer.childNodes.item(i).getAttribute("label") == "Toolbars")
  829.                 {
  830.                     toolbarPopup = toolbarContainer.childNodes.item(i).getElementsByTagName("menupopup").item(0);
  831.                    }
  832.             }
  833.             
  834.             var tempNode = document.createElement("menuitem");
  835.             tempNode.setAttribute("id", "view_gg_menuitem");
  836.             tempNode.setAttribute("label", "Googlebar");
  837.             tempNode.setAttribute("class", "menuitem-iconic");
  838.             tempNode.setAttribute("type", "checkbox");
  839.             tempNode.setAttribute("key", "key_googlebarShowHide");
  840.             tempNode.setAttribute("observes", "cmd_googlebarShowHide");
  841.             tempNode.setAttribute("accesskey", "G");
  842.             
  843.             if (toolbarPopup != null)
  844.             {
  845.                 toolbarPopup.appendChild(document.createElement("menuseparator"));
  846.                 toolbarPopup.appendChild(tempNode);
  847.                }
  848.             else
  849.             {
  850.                 toolbarContainer.appendChild(tempNode);
  851.             }
  852.         }
  853.  
  854.         myGooglebarUtil.logMessage('Initialized googlebar');
  855.     }
  856.     else {
  857.         googlebarGoPopupMenus();
  858.         updateUp();
  859.     }
  860. }
  861.  
  862. function ggb_LabelListener(e) {
  863.     if (e && e.attrName == 'checked') {
  864.         GB_PREF_OBJ.setBoolPref("showLabels", e.newValue == "true");
  865.         googlebarLabels();
  866.     }
  867. }
  868.  
  869. function ggb_OrdinalListener(e) {
  870.     if (e && e.attrName == 'checked') {
  871.         GB_PREF_OBJ.setBoolPref("lockOrdinals", e.newValue == "true");
  872.         googlebarOrdinals();
  873.     }
  874. }
  875.  
  876. function googlebarCustomNavigation()
  877. {
  878.     if (!window._content.document) {
  879.         return;
  880.     }
  881.  
  882.     var url = window._content.document.location;
  883.     var doc = window._content.document.documentElement;
  884.     var aElems = doc.getElementsByTagName("A");
  885.     var curr, last;
  886.  
  887.     var i = 0;
  888.     var count = 0;
  889.  
  890.     // Don't retrieve back to back duplicate links
  891.  
  892.     for (i = 0; i < aElems.length; i++) {
  893.         curr = getAnchorURL(aElems[i], url)
  894.         if (curr && last != curr) {
  895.             last = curr;
  896.             count++;
  897.         }
  898.     }
  899.  
  900.     if (count > 0) {
  901.         lastResults = new Array(count);
  902.     }
  903.     else {
  904.         lastResults = new Array(0);
  905.         googlebarCheckNavigation(-99);
  906.         return;
  907.     }
  908.  
  909.     count = 0;
  910.  
  911.     for (i = 0; i < aElems.length; i++) {
  912.         curr = getAnchorURL(aElems[i], url);
  913.         if (curr && last != curr) {
  914.             last = curr;
  915.             lastResults[count] = curr;
  916.             count++;
  917.         }
  918.     }
  919.  
  920.     // also populate the last google result and set up the button appropriately
  921.     lastGoogle = url;
  922.  
  923.     var lastBtn = myGooglebarUtil.getElement("last-button");
  924.     var lastBtnPop = myGooglebarUtil.getElement("last-button-popup");
  925.     lastBtn.removeAttribute("oncommand");
  926.     lastBtn.setAttribute("disabled", false);
  927.     lastBtn.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
  928.  
  929.     // clean up all of the popup menu items
  930.     for (i = lastBtnPop.childNodes.length - 1; i >= 0; i--) {
  931.         lastBtnPop.removeChild(lastBtnPop.childNodes[i]);
  932.     }
  933.     
  934.     setTimeout("googlebarCheckNavigation(-1)", 100);
  935. }
  936.  
  937. function getAnchorURL(element, baseURL)
  938. {
  939.     var href = element.getAttribute("href");
  940.     var url;
  941.  
  942.     if (!href || /^\s*mailto:/i.test(href)) {
  943.         return null;
  944.     }
  945.     else {
  946.         GB_URL_OBJ.spec = baseURL;
  947.         url = GB_URL_OBJ.resolve(href);
  948.     }
  949.  
  950.     if (url) {
  951.         return url;
  952.     }
  953.     else {
  954.     alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.getAnchorURL.1") + "\n" + href);
  955.         return null;
  956.     }
  957. }
  958.  
  959. function googlebarLoadResults()
  960. {
  961.     if (!window._content.document) {
  962.         return;
  963.     }
  964.  
  965.     var url = window._content.document.location;
  966.     if (/^\s*http:\/\/[^\.]*\.google\..*\/[^\?]*\?.*q=([^&]*)(&.*)*/i.test(url)) {
  967.         // Must have just loaded a google query result page
  968.         // so lets repopulate the array of last results.
  969.         //
  970.         // In a Google query result page all of the results
  971.         // are under HTML paragraph elements "P" with a class
  972.         // attribute of "g".  The first URL (child element "A")
  973.         // is the actual result that we care about.
  974.         var doc = window._content.document.documentElement;
  975.         var pElems = doc.getElementsByTagName("P");
  976.         var aElems;
  977.  
  978.         var i = 0;
  979.         var count = 0;
  980.  
  981.         for (i = 0; i < pElems.length; i++) {
  982.             if (pElems[i].getAttribute("class") == "g") {
  983.                 count++;
  984.             }
  985.         }
  986.  
  987.         if (count > 0) {
  988.             lastResults = new Array(count);
  989.         }
  990.         else {
  991.             lastResults = new Array(0);
  992.             return;
  993.         }
  994.  
  995.         count = 0;
  996.  
  997.         for (i = 0; i < pElems.length; i++) {
  998.             if (pElems[i].getAttribute("class") == "g") {
  999.                 aElems = pElems[i].getElementsByTagName("A");
  1000.                 if (aElems.length > 0) {
  1001.                     lastResults[count] = aElems[0].getAttribute("href");
  1002.                 }
  1003.                 count++;
  1004.             }
  1005.         }
  1006.  
  1007.         // also populate the last google result and set up the button appropriately
  1008.         lastGoogle = url;
  1009.  
  1010.         var lastBtn = myGooglebarUtil.getElement("last-button");
  1011.         var lastBtnPop = myGooglebarUtil.getElement("last-button-popup");
  1012.         lastBtn.removeAttribute("oncommand");
  1013.         lastBtn.setAttribute("disabled", false);
  1014.         lastBtn.setAttribute("onclick", "if (event.button == 1) { navGoMenu(event, '" + url + "', -1); event.preventBubble(); }");
  1015.         lastBtn.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
  1016.  
  1017.         // clean up all of the popup menu items
  1018.         for (i = lastBtnPop.childNodes.length - 1; i >= 0; i--) {
  1019.             lastBtnPop.removeChild(lastBtnPop.childNodes[i]);
  1020.         }
  1021.  
  1022.         var divElems = doc.getElementsByTagName("div");
  1023.         var divElem;
  1024.  
  1025.         for (i = 0; i < divElems.length; i++) {
  1026.             if (divElems[i].getAttribute("class") == "n") {
  1027.                 divElem = divElems[i];
  1028.                 break;
  1029.             }
  1030.         }
  1031.  
  1032.         if (divElem) {
  1033.             var urlRoot = url.toString().substring(0, url.toString().lastIndexOf("/"));
  1034.             var imgElems = divElem.getElementsByTagName("img");
  1035.             var imgSrc;
  1036.             var page;
  1037.             var tempNode;
  1038.             
  1039.             for (i = 0; i < imgElems.length; i++) {
  1040.                 imgSrc = imgElems[i].getAttribute("src");
  1041.  
  1042.                 if (imgSrc.indexOf("nav_previous") >= 0) {
  1043.                     url = urlRoot + imgElems[i].parentNode.getAttribute("href");
  1044.                     tempNode = document.createElement("menuitem");
  1045.                     tempNode.setAttribute("label", "Previous Result Page");
  1046.                     tempNode.setAttribute("tooltiptext", "Previous Result Page");
  1047.                     tempNode.setAttribute("class", "menuitem-all");
  1048.                     tempNode.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
  1049.                     lastBtnPop.appendChild(tempNode);
  1050.                     lastBtnPop.appendChild(document.createElement("menuseparator"));                
  1051.                 }
  1052.                 else if (imgSrc.indexOf("nav_current") >= 0) {
  1053.                     url = lastGoogle;
  1054.                     page = imgElems[i].parentNode.getElementsByTagName("span")[0].firstChild.nodeValue;
  1055.                     tempNode = document.createElement("menuitem");
  1056.                     tempNode.setAttribute("label", "Result Page " + page);
  1057.                     tempNode.setAttribute("tooltiptext", "Result Page " + page);
  1058.                     tempNode.setAttribute("class", "menuitem-all");
  1059.                     tempNode.setAttribute("type", "checkbox");
  1060.                     tempNode.setAttribute("checked", "true");
  1061.                     tempNode.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
  1062.                     lastBtnPop.appendChild(tempNode);                
  1063.                 }
  1064.                 else if (imgSrc.indexOf("nav_page") >= 0) {
  1065.                     url = urlRoot + imgElems[i].parentNode.getAttribute("href");
  1066.                     page = imgElems[i].parentNode.childNodes[2].nodeValue;
  1067.                     tempNode = document.createElement("menuitem");
  1068.                     tempNode.setAttribute("label", "Result Page " + page);
  1069.                     tempNode.setAttribute("tooltiptext", "Result Page " + page);
  1070.                     tempNode.setAttribute("class", "menuitem-all");
  1071.                     tempNode.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
  1072.                     lastBtnPop.appendChild(tempNode);                
  1073.                 }
  1074.                 else if (imgSrc.indexOf("nav_next") >= 0) {
  1075.                     url = urlRoot + imgElems[i].parentNode.getAttribute("href");
  1076.                     lastBtnPop.appendChild(document.createElement("menuseparator"));    
  1077.                     tempNode = document.createElement("menuitem");
  1078.                     tempNode.setAttribute("label", "Next Result Page");
  1079.                     tempNode.setAttribute("tooltiptext", "Next Result Page");
  1080.                     tempNode.setAttribute("class", "menuitem-all");
  1081.                     tempNode.setAttribute("oncommand", "navGoMenu(event, '" + url + "', -1); event.preventBubble();");
  1082.                     lastBtnPop.appendChild(tempNode);                
  1083.                 }
  1084.             }
  1085.         }
  1086.  
  1087.         setTimeout("googlebarCheckNavigation(-1)", 100);
  1088.     }
  1089. }
  1090.  
  1091. function googlebarCheckNavigation(resultIndx)
  1092. {
  1093.     if (!window._content.document) {
  1094.         return;
  1095.     }
  1096.     
  1097.     var prevBtn = myGooglebarUtil.getElement("prev-button");
  1098.     var nextBtn = myGooglebarUtil.getElement("next-button");
  1099.     var prevBtnPop = myGooglebarUtil.getElement("prev-button-popup");
  1100.     var nextBtnPop = myGooglebarUtil.getElement("next-button-popup");
  1101.     var ndx;
  1102.     
  1103.     // clean up all of the popup menu items
  1104.     for (ndx = prevBtnPop.childNodes.length - 1; ndx >= 0; ndx--) {
  1105.         prevBtnPop.removeChild(prevBtnPop.childNodes[ndx]);
  1106.     }
  1107.     for (ndx = nextBtnPop.childNodes.length - 1; ndx >= 0; ndx--) {
  1108.         nextBtnPop.removeChild(nextBtnPop.childNodes[ndx]);
  1109.     } 
  1110.  
  1111.     // if we didn't find a match then disable both buttons and return
  1112.     if (resultIndx == null || resultIndx < -1) {
  1113.         prevBtn.setAttribute("disabled", true);
  1114.         prevBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.prev.tooltip"));
  1115.         nextBtn.setAttribute("disabled", true);
  1116.         nextBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.next.tooltip"));
  1117.         return;
  1118.     }
  1119.     /*
  1120.     else if (lastResultIndx == resultIndx) {
  1121.         return;
  1122.     }
  1123.     */
  1124.     else {
  1125.         lastResultIndx = resultIndx;
  1126.     }
  1127.  
  1128.     // the oncommand attribute must be REMOVED because if
  1129.     // the button is disabled it should take no action and
  1130.     // if it is already set you can't just set it again,
  1131.     // for some reason that has no effect so you have to
  1132.     // remove the attribute and add it again
  1133.     // prevBtn.removeAttribute("oncommand");
  1134.     // nextBtn.removeAttribute("oncommand");
  1135.     
  1136.     var loc;
  1137.     var tempNode;
  1138.  
  1139.     // previous navigation
  1140.     if (lastResultIndx <= 0) {
  1141.         prevBtn.setAttribute("disabled", true);
  1142.         prevBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.prev.tooltip"));
  1143.     }
  1144.     else {
  1145.         ndx = lastResultIndx - 1;
  1146.         loc = lastResults[ndx];
  1147.         prevBtn.setAttribute("disabled", false);
  1148.         prevBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.prev.tooltip") + " - " + loc);
  1149.         prevBtn.setAttribute("oncommand", "navGo(event, 'prev-button-popup');");
  1150.         
  1151.         for (ndx = lastResultIndx - 1; ndx >= 0; ndx--) {
  1152.             loc = lastResults[ndx];
  1153.             tempNode = document.createElement("menuitem");
  1154.             tempNode.setAttribute("label", (ndx + 1) + " - " + loc);
  1155.             tempNode.setAttribute("class", "menuitem-all");
  1156.             tempNode.setAttribute("oncommand", "navGoMenu(event, '" + loc + "', " + ndx + "); event.preventBubble();");
  1157.             tempNode.setAttribute("nav-loc", loc);
  1158.             tempNode.setAttribute("nav-ndx", ndx);
  1159.             prevBtnPop.appendChild(tempNode);
  1160.         }
  1161.     }
  1162.  
  1163.     // next navigation
  1164.     if (lastResultIndx == lastResults.length - 1) {
  1165.         nextBtn.setAttribute("disabled", true);
  1166.         nextBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.next.tooltip"));
  1167.     }
  1168.     else {
  1169.         ndx = lastResultIndx + 1;
  1170.         loc = lastResults[ndx];
  1171.         nextBtn.setAttribute("disabled", false);
  1172.         nextBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.nav.next.tooltip") + " - " + loc);
  1173.         nextBtn.setAttribute("oncommand", "navGo(event, 'next-button-popup');");
  1174.         
  1175.         for (ndx = lastResultIndx + 1; ndx < lastResults.length; ndx++) {
  1176.             loc = lastResults[ndx];
  1177.             tempNode = document.createElement("menuitem");
  1178.             tempNode.setAttribute("label", (ndx + 1) + " - " + loc);
  1179.             tempNode.setAttribute("class", "menuitem-all");
  1180.             tempNode.setAttribute("oncommand", "navGoMenu(event, '" + loc + "', " + ndx + "); event.preventBubble();");
  1181.             tempNode.setAttribute("nav-loc", loc);
  1182.             tempNode.setAttribute("nav-ndx", ndx);            
  1183.             nextBtnPop.appendChild(tempNode);
  1184.         }
  1185.     }
  1186. }
  1187.  
  1188. function navGo(event, source)
  1189. {
  1190.     var navContainer = myGooglebarUtil.getElement(source);
  1191.  
  1192.     if (navContainer && navContainer.getElementsByTagName("menuitem").length > 0) {
  1193.         var tempNode = navContainer.getElementsByTagName("menuitem")[0];
  1194.         navGoMenu(event, tempNode.getAttribute("nav-loc"), parseInt(tempNode.getAttribute("nav-ndx")));
  1195.     }
  1196. }
  1197.  
  1198. function navGoMenu(event, addy, resultIndx)
  1199. {
  1200.     googlebarDoAction(addy, googlebarGetLocFromEvent(event));
  1201.     setTimeout("googlebarCheckNavigation(" + resultIndx + ")", 100);
  1202. }
  1203.  
  1204. ///////////////////////////////////////////////////////////////////////////////
  1205. ///////////////////////////////// Main Search /////////////////////////////////
  1206.  
  1207. function googlebarAutoSearch(event)
  1208. {
  1209.     googlebarInitPrefs();
  1210.     if (autoSearchOption) {
  1211.         googlebarSearch(event);
  1212.     }
  1213. }
  1214.  
  1215. function googlebarSearch(event, searchType, searchParams)
  1216. {
  1217.     var win = window._content.document;
  1218.     var searchURL;
  1219.  
  1220.     // recover any pref changes like country and modifiers immediately
  1221.     googlebarInitPrefs();
  1222.  
  1223.     if (!searchType) {
  1224.         searchType = googlebarGetActFromEvent(event);
  1225.     }
  1226.  
  1227.  
  1228.     // Some things cannot be done in a new tab, such as formfilling and capturing.
  1229.     // bailing out beforehand
  1230.     if(searchParams == "NO_SEARCH") {
  1231.  
  1232.         if(gbDoNonSearch(event, searchType, searchParams));
  1233.             return; // we are already done
  1234.     }
  1235.  
  1236.  
  1237.     if( gbLook4URL(event, searchType, searchParams)) {
  1238.         // hold on and let the user beware of what they put in here
  1239.         // we will get more on this
  1240.         // FIX ME need to escape illegal characters
  1241.         searchType = "doUrlNav" ;
  1242.         }
  1243.  
  1244.     if (!loading) {
  1245.         googlebarClearTerms();
  1246.         
  1247.         var critVal = myGooglebarUtil.trimString(myGooglebarUtil.getElement("googlebarCriteria").value);
  1248.         var noCriteria = true;
  1249.         
  1250.         if (critVal != "")
  1251.         {
  1252.             noCriteria = false;
  1253.             googlebarAddTerm(critVal);
  1254.             googlebarAddToHistory(critVal);
  1255.         }
  1256.  
  1257.         var crit = googlebarBuildURI(critVal);
  1258.  
  1259.         switch(searchType) {
  1260.  
  1261.         // TODO: Figure out which cases might not want to be searched if there is no search criteria
  1262.     
  1263.         case "site":
  1264.             if (noCriteria)
  1265.                 return;
  1266.         
  1267.             var searchHost;
  1268.  
  1269.             // If you are on a site search result then reuse that site for the next search,
  1270.             // otherwise use the current window location shown in the browser
  1271.  
  1272.             if (/^\s*http:\/\/[^\.]*\.google\..*\/[^\?]*\?.*q=site:([^\+]*)([^&]*)(&.*)*/i.test(win.location.href)) {
  1273.                 searchHost = RegExp.$1;
  1274.             }
  1275.             else {
  1276.                 searchHost = win.location.hostname;
  1277.             }
  1278.  
  1279.             searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=site:' + searchHost + '+' + crit;
  1280.             break;
  1281.     
  1282.         case "backwards":
  1283.             searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&q=link:' + googlebarInfoLocation();
  1284.             break;
  1285.     
  1286.         case "similar":
  1287.             searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&q=related:' + googlebarInfoLocation();
  1288.             break;
  1289.     
  1290.         case "translate":
  1291.             searchURL = 'http://translate.google.' + onlyInUSA + '/translate?sourceid=mozclient&u=' + googlebarInfoLocation();
  1292.             break;
  1293.  
  1294.         case "cachelink":
  1295.             if (!searchParams) {
  1296.               searchParams = 'http://www.google.com/';
  1297.             }
  1298.             searchURL = 'http://www.google.' + cntry2Srch + '/search?q=cache:' + searchParams;
  1299.             break;
  1300.     
  1301.         case "cache":
  1302.             searchURL = 'http://www.google.' + cntry2Srch + '/search?q=cache:' + googlebarInfoLocation();
  1303.             break;
  1304.     
  1305.         case "images":
  1306.                if (noCriteria)
  1307.                 searchURL = 'http://images.google.' + cntry2Srch + '/';
  1308.             else
  1309.                 searchURL = 'http://images.google.' + cntry2Srch + '/images?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit;
  1310.                 
  1311.             break;
  1312.     
  1313.         case "groups":
  1314.             if (noCriteria)
  1315.                 searchURL = 'http://groups.google.' + cntry2Srch + '/';
  1316.             else
  1317.                 searchURL = 'http://groups.google.' + cntry2Srch + '/groups?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit;
  1318.                 
  1319.             break;
  1320.     
  1321.         case "directory":
  1322.             if (noCriteria)
  1323.                 return;
  1324.                 
  1325.             searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit + '&cat=gwd/Top&sa=N&tab=gd';
  1326.             break;
  1327.     
  1328.         case "lucky":
  1329.             if (noCriteria)
  1330.                 return;
  1331.         
  1332.             searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit + '&btnI=I%27m+Feeling+Lucky';
  1333.             break;
  1334.  
  1335.         case "scholar":
  1336.             if (noCriteria)
  1337.                 searchURL = 'http://scholar.google.' + onlyInUSA + '/';
  1338.             else
  1339.                 searchURL = 'http://scholar.google.' + onlyInUSA + '/scholar?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit;
  1340.                 
  1341.             break;
  1342.     
  1343.         case "USA":
  1344.             if (noCriteria)
  1345.                 searchURL = 'http://www.google.' + onlyInUSA + '/unclesam';
  1346.             else
  1347.                 searchURL = 'http://www.google.' + onlyInUSA + '/unclesam?sourceid=mozclient&restrict=unclesam&ie=utf-8&oe=utf-8&q=' + crit;
  1348.                 
  1349.             break;
  1350.     
  1351.         case "Catalog":
  1352.             if (noCriteria)
  1353.                 searchURL = 'http://catalogs.google.' + onlyInUSA + '/';
  1354.             else
  1355.                 searchURL = 'http://catalogs.google.' + onlyInUSA + '/catalogs?sourceid=mozclient&ie=utf-8&oe=utf-8&q=' + crit;
  1356.                 
  1357.             break;
  1358.     
  1359.         case "bsd":
  1360.             if (noCriteria)
  1361.                 searchURL = 'http://www.google.' + cntry2Srch + '/bsd';
  1362.             else
  1363.                 searchURL = 'http://www.google.' + cntry2Srch + '/bsd?restrict=bsd&ie=utf-8&oe=utf-8&q=' + crit;
  1364.                 
  1365.             break;
  1366.     
  1367.         case "microsoft":
  1368.             if (noCriteria)
  1369.                 searchURL = 'http://www.google.' + cntry2Srch + '/microsoft';
  1370.             else
  1371.                 searchURL = 'http://www.google.' + cntry2Srch + '/microsoft?sourceid=mozclient&hq=microsoft&restrict=microsoft&ie=utf-8&oe=utf-8&q=' + crit;
  1372.                 
  1373.             break;
  1374.     
  1375.         case "mac":
  1376.                if (noCriteria)
  1377.                 searchURL = 'http://www.google.' + cntry2Srch + '/mac';
  1378.             else
  1379.                 searchURL = 'http://www.google.' + cntry2Srch + '/mac?sourceid=mozclient&restrict=mac&ie=utf-8&oe=utf-8&q=' + crit;
  1380.  
  1381.             break;
  1382.     
  1383.         case "linux":
  1384.             if (noCriteria)
  1385.                 searchURL = 'http://www.google.' + cntry2Srch + '/linux';
  1386.             else
  1387.                 searchURL = 'http://www.google.' + cntry2Srch + '/linux?sourceid=mozclient&restrict=linux&ie=utf-8&oe=utf-8&q=' + crit;
  1388.                 
  1389.             break;
  1390.     
  1391.         case "news":
  1392.             if (noCriteria)        
  1393.                 searchURL = googlebarNewsLocation();
  1394.             else
  1395.                 searchURL = 'http://news.google.' + onlyInUSA + '/news?sourceid=mozclient&ie=utf-8&oe=utf-8&' + cntryNews2Srch + '&q=' + crit;
  1396.                 
  1397.             break;
  1398.  
  1399.         case "answers":
  1400.             if (noCriteria)
  1401.                 searchURL = 'http://answers.google.' + onlyInUSA + '/';
  1402.             else
  1403.                 searchURL = 'http://answers.google.' + onlyInUSA + '/answers/main?cmd=search&qtype=all&q=' + crit;
  1404.                 
  1405.             break;
  1406.     
  1407.         case "webquotes":
  1408.             if (noCriteria)
  1409.                 return;
  1410.         
  1411.             searchURL = 'http://labs.google.' + onlyInUSA + '/cgi-bin/webquotes?num_quotes=3&q=' + crit + '&btnG=Google+WebQuotes+Search&show_titles=1&bold_links=1&snippet_threshold=3&ie=utf-8&oe=utf-8';
  1412.             break;
  1413.     
  1414.         case "stocks":
  1415.             if (noCriteria)
  1416.                 return;
  1417.  
  1418.             searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=stocks:' + crit;
  1419.             break;
  1420.     
  1421.         case "viewer":
  1422.             if (noCriteria)
  1423.                 return;
  1424.  
  1425.             searchURL = 'http://labs1.google.' + onlyInUSA + '/cgi-bin/gviewer.cgi?q=' +crit + '&btnG=Google+Search&ie=utf-8&oe=utf-8';
  1426.             break;
  1427.     
  1428.         case "froogle":
  1429.             if (noCriteria)
  1430.                 searchURL = 'http://froogle.google.' + onlyInUSA + '/';
  1431.             else
  1432.                 searchURL = 'http://froogle.google.' + onlyInUSA + '/froogle?q=' + crit + '&btnG=Froogle+Search&ie=utf-8&oe=utf-8';
  1433.  
  1434.             break;
  1435.     
  1436.         case "dictionary":
  1437.             if (noCriteria)
  1438.                 searchURL = 'http://www.dictionary.com/';
  1439.             else
  1440.                 searchURL = 'http://www.dictionary.com/cgi-bin/dict.pl?term=' + crit;
  1441.             
  1442.             break;
  1443.     
  1444.         case "glossary":
  1445.                if (noCriteria)
  1446.                 return;
  1447.         
  1448.             // searchURL = 'http://labs.google.' + cntry2Srch + '/glossary?q=' + crit;
  1449.             // Glossary search doesn't appear to be valid for countries outside the US
  1450.             // searchURL = 'http://labs.google.' + onlyInUSA + '/glossary?q=' + crit;
  1451.             searchURL = 'http://www.google.' + onlyInUSA + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=define:' + crit;
  1452.             break;
  1453.  
  1454.         case "gb-mycountry":
  1455.                if (noCriteria)
  1456.                 return;
  1457.         
  1458.             searchURL = 'http://www.google.' + cntry2Srch + '/search?&cr=' + mycntry2Srch + '&lr=' + mylang2Srch + '&q=' + crit ;
  1459.             break;
  1460.  
  1461. // XXX
  1462.         case "gb-mylocal":
  1463.  
  1464.             var s1 = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.gbmylocal.msg");
  1465.             var s2 = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.gbmylocal.initial");
  1466.             var s3 = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.gbmylocal.title");
  1467.  
  1468.             try {
  1469.                 gbmylocalString = GB_PREF_OBJ.getCharPref("gbmylocalPref");
  1470.             }
  1471.             catch(e) {
  1472.                 myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  1473.  
  1474.                 //msg, initial, parent, title
  1475.                 //returns user input through initial
  1476.     
  1477.                 gbmylocalString=gbprompt( s1, s2, window, s3); 
  1478.  
  1479.                 if(gbmylocalString)
  1480.                     GB_PREF_OBJ.setCharPref("gbmylocalPref", gbmylocalString);  // Default
  1481.                 else
  1482.                     GB_PREF_OBJ.setCharPref("gbmylocalPref", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mylocalPrefDef" ));
  1483.  
  1484.                 gbmylocalString = GB_PREF_OBJ.getCharPref("gbmylocalPref");
  1485.             }
  1486.  
  1487.             // shift and middle mousebutton
  1488.             if(event.shiftKey && searchParams == "REPROGRAM" ) {
  1489.                 gbmylocalString=gbprompt( s1, gbmylocalString, window, s3);
  1490.  
  1491.                 if(gbmylocalString)
  1492.                     GB_PREF_OBJ.setCharPref("gbmylocalPref", gbmylocalString);  // Default
  1493.                 else
  1494.                     GB_PREF_OBJ.setCharPref("gbmylocalPref", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mylocalPrefDef" ));
  1495.             }
  1496.             if(gbmylocalString) {
  1497.             searchURL = 'http://local.google.' + cntry2Srch + '/local?&near=' + gbmylocalString + '&q=' + crit + '&btnG=Google+Search&ie=utf-8&oe=utf-8';
  1498.             break;
  1499.             }
  1500.             else
  1501.             return;
  1502.     
  1503.         case "gblogger":
  1504.         // do not put mozclient in... else sort by date will mess this one up.
  1505.             // var gbloggerStandardWinPref ;
  1506.             try {
  1507.                 gbloggerStandardWinPref = GB_PREF_OBJ.getBoolPref("gbloggerStandardWinPref");
  1508.             }
  1509.             catch(e) {
  1510.                 gbloggerStandardWinPref = false;
  1511.                 GB_PREF_OBJ.setBoolPref("gbloggerStandardWinPref", true );
  1512.                 myGooglebarUtil.logMessage("\n***Gblogger error\n" + e + "\n");
  1513.             }
  1514.             
  1515.         if( gbloggerStandardWinPref ){
  1516.         var Q='';
  1517.         var x=window._content; // was document, moz complains;
  1518.         var y=window._content;
  1519.             if(x.selection){Q=x.selection.createRange().text;}
  1520.             else if(y.getSelection){Q=y.getSelection();}
  1521.             else if(x.getSelection){Q=x.getSelection();}
  1522.             // void(window.open('http://www.blogger.com/blog_this.pyra?t='+escape(Q)+'&u='+escape(location.href)+'&n='+escape(document.title)));
  1523.             void(window.open('http://www.blogger.com/blog_this.pyra?t='+escape(Q)+'&u='+escape(x.location.href)+'&n='+escape(x.document.title),'bloggerForm','scrollbars=no,width=475,height=300,top=175,left=75,status=yes,resizable=yes'));
  1524.  
  1525.             return;
  1526.         }
  1527.         else {
  1528.  
  1529.         Q="";
  1530.         x=window._content; // .document;
  1531.         y=window._content;
  1532.  
  1533.             if(x.selection) //this is deprecated, I haven't seen it true yet either
  1534.                 {Q=x.selection.createRange().text;}
  1535.  
  1536.             else 
  1537.             if(y.getSelection)
  1538.                 {Q=y.getSelection();}
  1539.  
  1540.             else
  1541.             if(x.getSelection)
  1542.                 {Q=x.getSelection();}
  1543.  
  1544.  
  1545.             searchURL = 'http://www.blogger.' + onlyInUSA + '/blog_this.pyra?t='+escape(Q)+'&u='+escape(x.location.href)+'&n='+escape(x.document.title) ;
  1546.  
  1547.             }            
  1548.             break;
  1549.  
  1550.         case "university":
  1551.             if (!university) {
  1552.                 alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.univ.none"));
  1553.                 return;
  1554.             }
  1555.             
  1556.             if (noCriteria) {
  1557.                 searchURL = university;
  1558.             }
  1559.             else if (universityName == "All Universities") {
  1560.                 searchURL = university + '&q=' + crit;
  1561.             }
  1562.             else {
  1563.                 searchURL = university + '?q=' + crit;
  1564.             }
  1565.             
  1566.             break;
  1567.     
  1568.         case "nocalc":
  1569.             if (noCriteria)
  1570.                 return;
  1571.         
  1572.             searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=%2B' + crit + '&nocalc=1';
  1573.             break;
  1574.  
  1575.         case "doUrlNav":
  1576.             searchURL = myGooglebarUtil.getElement("googlebarCriteria").value;
  1577.             break;
  1578.             
  1579.         default:
  1580.             /*
  1581.             if (labsOption) {
  1582.                 searchURL = 'http://labs.google.com/cgi-bin/keys?q=';
  1583.             }
  1584.             else {
  1585.                 searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=';
  1586.             }
  1587.             */
  1588.             
  1589.             searchURL = 'http://www.google.' + cntry2Srch + '/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=';
  1590.             searchURL += crit;
  1591.             break;
  1592.  
  1593.         }
  1594.  
  1595.         if (sortByDate) {
  1596.             searchURL = searchURL.replace('sourceid=mozclient','sourceid=mozclient&scoring=d');
  1597.         }
  1598.         if (resultLimit > 0) {
  1599.             searchURL = searchURL.replace('sourceid=mozclient','sourceid=mozclient&num=' + resultLimit);
  1600.         }
  1601.  
  1602.         googlebarDoAction(searchURL, googlebarGetLocFromEvent(event));
  1603.     }
  1604. }
  1605.  
  1606. function googlebarGetLocFromEvent(event)
  1607. {
  1608.     // alert("ALT : " + event.altKey + "\nCTRL : " + event.ctrlKey + "\nSHIFT : " + event.shiftKey + "\n");
  1609.     if (event.button == 1) {
  1610.         return "New Tab";
  1611.     }
  1612.     if (event.altKey) {
  1613.         if (event.ctrlKey) {
  1614.             return arrDeckLocs[altCtrlLocation];
  1615.         }
  1616.         else if (event.shiftKey) {
  1617.             return arrDeckLocs[altShiftLocation];
  1618.         }
  1619.         else {
  1620.             return arrDeckLocs[altLocation];
  1621.         }
  1622.     }
  1623.     else if (event.ctrlKey) {
  1624.         if (event.shiftKey) {
  1625.             return arrDeckLocs[ctrlShiftLocation];
  1626.         }
  1627.         else {
  1628.             return arrDeckLocs[ctrlLocation];
  1629.         }
  1630.     }
  1631.     else if (event.shiftKey) {
  1632.         return arrDeckLocs[shiftLocation];
  1633.     }
  1634.     else {
  1635.         return arrDeckLocs[noneLocation];
  1636.     }
  1637. }
  1638.  
  1639. function googlebarGetActFromEvent(event)
  1640. {
  1641.     if (event.altKey) {
  1642.         if (event.ctrlKey) {
  1643.             return arrDeckActs[altCtrlAction];
  1644.         }
  1645.         else if (event.shiftKey) {
  1646.             return arrDeckActs[altShiftAction];
  1647.         }
  1648.         else {
  1649.             return arrDeckActs[altAction];
  1650.         }
  1651.     }
  1652.     else if (event.ctrlKey) {
  1653.         if (event.shiftKey) {
  1654.             return arrDeckActs[ctrlShiftAction];
  1655.         }
  1656.         else {
  1657.             return arrDeckActs[ctrlAction];
  1658.         }
  1659.     }
  1660.     else if (event.shiftKey) {
  1661.         return arrDeckActs[shiftAction];
  1662.     }
  1663.     else {
  1664.         return arrDeckActs[noneAction];
  1665.     }
  1666. }
  1667.  
  1668. function googlebarInfoLocation()
  1669. {
  1670.     var win = window._content.document;
  1671.     var location;
  1672.  
  1673.     if (/^\s*http:\/\/[^\.]*\.google\..*\/[^\?]*\?.*(q=link:|q=related:|q=site:|u=)([^\+]*)([^&]*)(&.*)*/i.test(win.location.href)) {
  1674.         location = RegExp.$2;
  1675.     }
  1676.     else if (/^\s*http:\/\/.*\/[^\?]*\?.*q=cache:([^\+]*)([^&]*)(&.*)*/i.test(win.location.href)) {
  1677.         location = RegExp.$1;
  1678.     }
  1679.     else {
  1680.         location = win.location;
  1681.     }
  1682.     
  1683.     return escape(location);
  1684. }
  1685.  
  1686. function googlebarNewsLocation()
  1687. {
  1688.     var location = 'http://news.google.' + onlyInUSA + cntryNewsSite;
  1689.     return location;
  1690. }
  1691.  
  1692. function googlebarDoAction(searchURL, location)
  1693. {
  1694.     switch(location) {
  1695.  
  1696.     case "Same Window":
  1697.         window._content.document.location = searchURL;
  1698.  
  1699.         // if we are using google labs for the search, then we
  1700.         // want to make sure that we return the focus to the
  1701.         // main navigator window
  1702.         /*
  1703.         if (labsOption) {
  1704.             window.frames[0].focus();
  1705.         }
  1706.         else {
  1707.             window.content.focus();
  1708.         }
  1709.         */
  1710.         
  1711.         window.content.focus();
  1712.         break;
  1713.  
  1714.     case "New Tab":
  1715.         var browser = getBrowser();
  1716.         var tab = browser.addTab(searchURL, getReferrer(document));
  1717.         window.content.focus();
  1718.  
  1719.         // Hook this up -- have we init'ed GB_ROOT_OBJ
  1720.         //if (!GB_ROOT_OBJ.getBoolPref("browser.tabs.loadInBackground")) {
  1721.         if (!GB_ROOT_OBJ.getBoolPref("browser.tabs.loadBookmarksInBackground")) {
  1722.             browser.selectedTab = tab;
  1723.         }
  1724.         break;
  1725.  
  1726.     case "New Window":
  1727.         window.open(searchURL);
  1728.         break;
  1729.  
  1730.     default:
  1731.         alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.error"));
  1732.         break;
  1733.  
  1734.     }
  1735. }
  1736.  
  1737. ///////////////////////////////////////////////////////////////////////////////
  1738. /////////////////////////////////// Support ///////////////////////////////////
  1739.  
  1740. function googlebarEscape(term)
  1741. {
  1742.     // we need to handle both '/' and '+' specially
  1743.     term = encodeURIComponent(term);
  1744.     return term.replace(/\+/g,"%2B").replace(/\//g,"%2F");
  1745. }
  1746.  
  1747. function googlebarBuildURI(criteria)
  1748. {
  1749.     var terms = criteria.split(" ");
  1750.     var uri = "";
  1751.  
  1752.     for (var i = 0; i < terms.length; i++) {
  1753.         if (i > 0) {
  1754.             uri += "+";
  1755.         }
  1756.         uri += googlebarEscape(terms[i]);
  1757.     }
  1758.     return uri;
  1759. }
  1760.  
  1761. function googlebarPaste(event)
  1762. {
  1763.     var critBox = myGooglebarUtil.getElement("googlebarCriteria");
  1764.     var textBox;
  1765.  
  1766.     // attempt to grab selected text from the current document (tab)
  1767.     var text = _content.document.getSelection();
  1768.  
  1769.     // if nothing selected in the document then perhaps there is a
  1770.     // selection contained within a frame of the current document
  1771.     if (!text) {
  1772.         for (var i = 0; i < _content.frames.length; i++) {
  1773.             text = _content.frames[i].document.getSelection();
  1774.             if (text) break;
  1775.         }
  1776.     }
  1777.  
  1778.     // if still no text has been found then perhaps something in
  1779.     // the the location text box has been selected
  1780.     if (!text) {
  1781.         textBox = window.document.getElementById("urlbar");
  1782.         if (textBox.selectionStart >= 0) {
  1783.             text = textBox.value.substring(textBox.selectionStart, textBox.selectionEnd);
  1784.         }
  1785.     }
  1786.  
  1787.     // if still no text has been found then perhaps something in
  1788.     // the the criteria box has been selected - not sure why you
  1789.     // would want to search on something already in the criteria
  1790.     // box but hey, who am I to criticize
  1791.     // hmmm, here is a far fetched use case so I'll leave this code
  1792.     // for now - someone may have multiple terms in the criteria
  1793.     // box and may want to only search on one of them, highlighting
  1794.     // that single term and then shift+click on highlight search
  1795.     // button would search on that term alone - not likely, but a use case
  1796.     if (!text) {
  1797.         textBox = myGooglebarUtil.getElement("googlebarCriteria");
  1798.         if (textBox.selectionStart >= 0) {
  1799.             text = textBox.value.substring(textBox.selectionStart, textBox.selectionEnd);
  1800.         }
  1801.     }
  1802.  
  1803.     // if we have found some selected text then set the criteria
  1804.     // box to that value and reset the search term buttons,
  1805.     // otherwise display an error message via an alert
  1806.     if (text) {
  1807.  
  1808.         // if there was no previous text or the shift key was pressed
  1809.         // then change the value to the selected text, otherwise append
  1810.         // the text to the end of what was already there.  after that
  1811.         // then the search term buttons need to be updated
  1812.  
  1813.         if (!critBox.value){
  1814.             critBox.value = text;
  1815.         }
  1816.         else
  1817.         {
  1818.             if(event.shiftKey) {
  1819.                 srch4SelAppnd ? critBox.value = text : critBox.value += " " + text;
  1820.             }
  1821.             else {
  1822.                 srch4SelAppnd ? critBox.value += " " + text : critBox.value = text;
  1823.             }
  1824.         }
  1825.  
  1826.     var savedPref;
  1827.  
  1828.     try {
  1829.         // Just sneak in a pref change for this
  1830.         // one search and reset it when done.
  1831.         // better have this already!!
  1832.         savedPref = noneLocation ;
  1833.         GB_PREF_OBJ.setCharPref("LocationNone", "1");  // New Tab
  1834.  
  1835.         // New text in box, so update the buttons...
  1836.         googlebarCheckSearchbuttons();
  1837.         // Do it.
  1838.         if(srch4SelAppnd == event.shiftKey)
  1839.             googlebarSearch(event);
  1840.  
  1841.         GB_PREF_OBJ.setCharPref("LocationNone", savedPref);
  1842.     }
  1843.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  1844.     myGooglebarUtil.logMessage("\nCouldn't set LocationNone pref for googlebarPaste\n");
  1845.     }
  1846.  
  1847.  
  1848.     }
  1849.     else {
  1850. // Still NO text!!!
  1851. // Now we'll look for forms input boxes
  1852. // yes, try and get the text
  1853. // no, emit our default nothing selected msg early on!!!
  1854.         
  1855.        var formsArray = content.document.forms;
  1856.        if (!formsArray) {
  1857.             alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.select_before"));
  1858.             return;
  1859.        }
  1860.  
  1861.        var form;
  1862.  
  1863.        for (form=0; form<formsArray.length; form++) {
  1864.          var elementsArray = formsArray[form].elements;
  1865.          var element;
  1866.  
  1867.          for (element=0; element < elementsArray.length; element++) {
  1868.          var type = elementsArray[element].type;
  1869.            if ((type=="text") || (type=="textarea")) {
  1870.              if( elementsArray[element].selectionStart != elementsArray[element].selectionEnd) {
  1871.                // stuffit into our criteriaBox
  1872.              text = elementsArray[element].value.substring(elementsArray[element].selectionStart, elementsArray[element].selectionEnd);
  1873.              critBox.value = text;
  1874.             
  1875.             try {
  1876.                 // Just sneak in a pref change for this
  1877.                 // one search and reset it when done.
  1878.                 // could call it like this but... 
  1879.                 // GB_PREF_OBJ.getCharPref("LocationNone"); 
  1880.                 // better have this already!!
  1881.  
  1882.                 savedPref = noneLocation ;  
  1883.                 GB_PREF_OBJ.setCharPref("LocationNone", "1");  // New Tab as default
  1884.                 
  1885.                 // New text in box, so update the buttons...
  1886.                 googlebarCheckSearchbuttons();
  1887.                 // Do it
  1888.                 googlebarSearch(event);
  1889.                 GB_PREF_OBJ.setCharPref("LocationNone", savedPref);
  1890.             }
  1891.             catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  1892.                 myGooglebarUtil.logMessage("\nCouldn't set LocationNone pref for googlebarPaste\n");
  1893.             }
  1894.  
  1895.  
  1896.      } // Selection start and end are different
  1897.  
  1898.     } // ((type=="") || (type=="text") || (type=="input")) 
  1899.    } // for (element=0; element < elementsArray.length; element++) 
  1900.   } // for (form=0; form<formsArray.length; form++) 
  1901.  } // else 
  1902.  
  1903.  
  1904. }
  1905.  
  1906. function googlebarFindTerms(criteria)
  1907. {
  1908.     //  quotes only matter when preceded by a space or a quote.
  1909.     var terms    = new Array();
  1910.     var val, testIndx, spaceIndx;
  1911.     var tempval  = criteria;
  1912.     var inQuote  = false;
  1913.     var haveTerm = false;
  1914.  
  1915.     var currPtr  = 0;    // the start of the current term
  1916.     var prevChar = ' ';  // the char we last saw
  1917.     
  1918.     // JW. I have little experience with this function but what was there would only handle one word.
  1919.     // So I hope this doesn't break things.
  1920.     try { testIndx = tempval.search(/(cache|link|related|stocks|define|site|allintitle|intitle|allinurl|inurl|filetype|group):/g); }
  1921.         catch(e){ } // nothing
  1922.     
  1923.     if (testIndx >= 0) {
  1924.         spaceIndx = tempval.indexOf(" ");
  1925.         
  1926.         if (spaceIndx >= 0 && spaceIndx < testIndx)
  1927.             criteria = tempval.slice(0, testIndx);
  1928.         else
  1929.             criteria = "";
  1930.   
  1931.         criteria += tempval.slice(1 + tempval.indexOf(":"), tempval.length);
  1932.     }
  1933.     
  1934.     for (var index = 0; index < criteria.length; index++) {
  1935.         var currChar = criteria.charAt(index);
  1936.  
  1937.         switch (currChar) {
  1938.           
  1939.         case ' ':
  1940.         // case '+':
  1941.         case '(':
  1942.         case ')':
  1943.         case '~':
  1944.           // these characters do not occur on the search term buttons, 
  1945.           // except in quoted phrases
  1946.           if (!inQuote && haveTerm) {
  1947.             val = myGooglebarUtil.trimString(criteria.substring(currPtr, index));
  1948.             if (!myGooglebarUtil.inArray(terms, val)) {
  1949.               if (val != 'OR' && val[0] != '-') {
  1950.                 terms.push(val);
  1951.               }
  1952.             }
  1953.             haveTerm = false;
  1954.           }
  1955.           break;
  1956.           
  1957.         case '"':
  1958.           // phrases (enclosed in "") should result in only one button
  1959.           if (!inQuote) {
  1960.               if (haveTerm) {
  1961.                   val = myGooglebarUtil.trimString(criteria.substring(currPtr, index));
  1962.                   if (!myGooglebarUtil.inArray(terms, val)) {
  1963.                       terms.push(val);
  1964.                   }
  1965.                   haveTerm = false;
  1966.               }
  1967.  
  1968.               // any of the discardable characters can occur before a phrase
  1969.               if ((prevChar == ' ') 
  1970.                   || (prevChar == '"')
  1971.                   || (prevChar == '(')
  1972.                   || (prevChar == ')')
  1973.                   || (prevChar == '+')
  1974.                   || (prevChar == '~')
  1975.                 ) {
  1976.                   inQuote = true;
  1977.               }
  1978.           }
  1979.           else {
  1980.               if (haveTerm) {
  1981.                 val = /*myGooglebarUtil.trimString(*/criteria.substring(currPtr, index)/*)*/;
  1982.                   if (!myGooglebarUtil.inArray(terms, val)) {
  1983.                       terms.push(val);
  1984.                   }
  1985.                   haveTerm = false;
  1986.                   inQuote = false;
  1987.               }
  1988.           }
  1989.           break;
  1990.           
  1991.         default:
  1992.             if (!haveTerm) {
  1993.                 haveTerm = true;
  1994.                 currPtr = index;
  1995.             }
  1996.         }
  1997.         prevChar = currChar;
  1998.     }
  1999.     val = myGooglebarUtil.trimString(criteria.substring(currPtr, index));
  2000.     // FIX ME this only gets executed on the last term in a group
  2001.     // I'll leave it for now. jw.
  2002.     if (haveTerm && !myGooglebarUtil.inArray(terms, val) ) {
  2003.       // remove special prefixes
  2004.       val = val.replace(/(cache|link|related|stocks|define|site|allintitle|intitle|allinurl|inurl|filetype|group):/,'');
  2005.       
  2006.       if (val != 'OR' && val[0] != '-') {
  2007.         terms.push(val);
  2008.       }
  2009.     }
  2010.     
  2011.     return terms;
  2012. }
  2013.  
  2014. function googlebarAddToHistory(term, ignorePref)
  2015. {
  2016.     // This function adds the string "term" to the search
  2017.     // history *only* if it is not already there
  2018.     // Robert, we should probably remove the term from it's location in the list,
  2019.     // and then put it at the top of the list. My favorite terms roll off the list,
  2020.     // even when I use them frequently. waddya think? jw
  2021.  
  2022.     var critBox = myGooglebarUtil.getElement("googlebarCriteria");
  2023.     var historyMenu = critBox.childNodes.item(0);
  2024.  
  2025.     var numHistItems = historyMenu.childNodes.length;
  2026.     var alreadyInHist = false;
  2027.     var i = 0;
  2028.  
  2029.     // iterate over the current history and check if the term is
  2030.     // already there
  2031.     for (i = 0; i < numHistItems; i++) {
  2032.         if (term == historyMenu.childNodes[i].getAttribute("label")) {
  2033.             alreadyInHist = true;
  2034.         }
  2035.     }
  2036.  
  2037.     // add to history
  2038.     if (!alreadyInHist) {
  2039.         var myMenuItem = document.createElement("menuitem");
  2040.         myMenuItem.setAttribute("label", term);
  2041.         myMenuItem.setAttribute("oncommand", "googlebarAutoSearch(event);");
  2042.  
  2043.         if (numHistItems <= 0) {
  2044.             historyMenu.appendChild(myMenuItem);
  2045.         }
  2046.         else {
  2047.             historyMenu.insertBefore(myMenuItem, historyMenu.childNodes[0]);
  2048.         }
  2049.  
  2050.         numHistItems++;
  2051.  
  2052.         if (!ignorePref) {
  2053.             googlebarAddToHistoryPref(term);
  2054.         }
  2055.  
  2056.         // if too many items have been added then remove extra items from the bottom
  2057.         if (numHistItems > maxHistCnt) {
  2058.             var numToRemove = numHistItems - maxHistCnt;
  2059.  
  2060.             // iterate over the current history and remove any extraneous items
  2061.             for (i = 1; i <= numToRemove; i++) {
  2062.                 historyMenu.removeChild(historyMenu.lastChild);
  2063.             }
  2064.             googlebarRefreshHistoryPref();
  2065.         }
  2066.     }
  2067. }
  2068.  
  2069. function googlebarAddToHistoryPref(term)
  2070. {
  2071.     // This function adds the string "term" to the search
  2072.     // history preference *only* if the option to save
  2073.     // search history is selected.
  2074.     //
  2075.     // This function should only be called after it has
  2076.     // been established that this item is not already
  2077.     // in the list of items (see googlebarAddToHistory)
  2078.     // otherwise there may be duplicate items added to
  2079.     // the history.  There could be a check to see whether
  2080.     // it exists here as well to prevent this problem
  2081.     // but it doesn't appear to be necessary at this point
  2082.     // since this function is only called from within the
  2083.     // googlebarAddToHistory function.
  2084.     //
  2085.     // Another potential problem that should be addressed
  2086.     // is to check whether or not the || delimeter is
  2087.     // contained in the search term, if it is then it will
  2088.     // cause a problem when the history is reloaded.
  2089.  
  2090.     if (historyOption) {
  2091.         var sHistory = "";
  2092.         var sSearch = term;
  2093.  
  2094.         if (!sSearch) {
  2095.             return;
  2096.         }
  2097.  
  2098.         try {
  2099.             sHistory = GB_PREF_OBJ.getComplexValue("history", GB_STRING_FLAG).data;
  2100.         }
  2101.         catch(e) {
  2102.             myGooglebarUtil.logMessage("\nHistory get pref err\n" + e );
  2103.             sHistory = GB_PREF_OBJ.setCharPref("history", "placeholder");
  2104.         }
  2105.  
  2106.         if (sHistory) {
  2107.             sHistory = sHistory + sep + sSearch;
  2108.         }
  2109.         else {
  2110.             sHistory = sSearch;
  2111.         }
  2112.  
  2113.         var string = new GB_STRING_CONSTRUCTOR;
  2114.         string.data = sHistory;
  2115.         GB_PREF_OBJ.setComplexValue("history", GB_STRING_FLAG, string);
  2116.     }
  2117. }
  2118.  
  2119. function googlebarRefreshHistoryPref()
  2120. {
  2121.     var critBox = myGooglebarUtil.getElement("googlebarCriteria");
  2122.     var historyMenu = critBox.childNodes.item(0);
  2123.     var numHistItems = historyMenu.childNodes.length;
  2124.  
  2125.     // sync up the history preference with the new list
  2126.     GB_PREF_OBJ.setCharPref("history", "");
  2127.  
  2128.     for (i = numHistItems - 1; i >= 0; i--) {
  2129.         googlebarAddToHistoryPref(historyMenu.childNodes[i].getAttribute("label"));
  2130.     }
  2131. }
  2132. // XXX
  2133. function googlebarClearHistory(aflag)
  2134. {
  2135.     // introduced a parm to indicate whether to clear the critBox and search buttons
  2136.     // true when called by user, false when used otherwise.
  2137.     
  2138.     // This function removes all items from the search
  2139.     // history (both history pref and popup menu)
  2140.     var critBox = myGooglebarUtil.getElement("googlebarCriteria");
  2141.  
  2142.     if (!critBox) {
  2143.         alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.googlebarClearHistory.1"));
  2144.         return;
  2145.     }
  2146.  
  2147.     var saveCurrCrit = critBox.value;
  2148.     var historyMenu = critBox.childNodes.item(0);
  2149.     var numHistItems = historyMenu.childNodes.length;
  2150.  
  2151.  
  2152.     // iterate over the current history and remove each item
  2153.     for (var i = numHistItems - 1; i >= 0; i--) {
  2154.         historyMenu.removeChild(historyMenu.childNodes[i]);
  2155.     }
  2156.  
  2157.     // next clear all the term buttons, the input field
  2158.     // (by setting selected index to -1), and history pref
  2159.     googlebarClearTerms();
  2160.     critBox.selectedIndex = -1;
  2161.     GB_PREF_OBJ.setCharPref("history", "");
  2162.     
  2163.     // When the history is cleared all highlighting must be removed
  2164.     myGooglebarHighlight.checkHighlight("");
  2165.  
  2166.     // some people want this cleared, bug 6430, 6462
  2167.     // so... when invoked by user actions, we don't restore it
  2168.     // only invoked in the main pulldown menu at present.
  2169.     if(!aflag){
  2170.         if(saveCurrCrit)
  2171.         critBox.value=saveCurrCrit;
  2172.         googlebarAddTerm(saveCurrCrit);
  2173.     }
  2174. }
  2175.  
  2176. function googlebarAddTerm(term)
  2177. {
  2178.     var critBox = myGooglebarUtil.getElement("googlebarCriteria");
  2179.     var mySearchTermBox = myGooglebarUtil.getElement("googlebarSearchTerms");
  2180.     var mySearchTermMenu = myGooglebarUtil.getElement("searchterms-menu");
  2181.     var mySearchTermPopup = myGooglebarUtil.getElement("searchterms-popup");
  2182.     var myTerms = googlebarFindTerms(term);
  2183.     var tempNode, tempValue;
  2184.     var searchTermWidth = 0;
  2185.     var availableWidth = googlebarAvailableWidth();
  2186.     mySearchTermBox.setAttribute("googlebaroverflow",false);
  2187.     var overflow = false;
  2188.  
  2189.     for (var i = 0; i < myTerms.length; i++) {
  2190.         tempNode = document.createElement("text");
  2191.         tempNode.setAttribute("value", myTerms[i]);
  2192.         //tempNode.setAttribute("className", "googleBarSearchTerm");
  2193.         tempNode.className = "googleBarSearchTerm";
  2194.         tempValue = myTerms[i].replace(/\\/, "\\\\");
  2195.         tempNode.setAttribute("onclick", "googlebarFindInPage(\"" + tempValue + "\" \,event \)");
  2196.  
  2197.         if (myGooglebarHighlight.isHighlightOn()) {
  2198.             // for some reason, the following line does not work (the style attribute is set 
  2199.             // but not honored by mozilla), so we have to use a global class
  2200.             
  2201.             // RF - 2005/01/25
  2202.             // the style seems to be working in newer versions of firefox and mozilla
  2203.             // and we want to use the new modifiable array of colors and not the predetermined
  2204.             // styles in the stylesheet if at all possible.  this likely needs testing.
  2205.             // would be nice to not have to enumerate all 120+ new colors as styles in the
  2206.             // stylesheet if at all possible.
  2207.             //
  2208.             // tempNode.className = "googleBarSearchTerm coloredSearchTerm"+(i%10);
  2209.             
  2210.             tempNode.setAttribute("style", "background-color:" + myGooglebarHighlight.getTermColors()[i%10]);
  2211.             tempNode.className = "googleBarSearchTerm";
  2212.         }
  2213.         mySearchTermBox.appendChild(tempNode);
  2214.         searchTermWidth = mySearchTermBox.boxObject.width;
  2215.  
  2216.         // check if buttons fit, if not, remove the last button
  2217.         // and add it to the overflow menu
  2218.         if (searchTermWidth > availableWidth) {
  2219.             mySearchTermPopup.appendChild(tempNode);
  2220.             mySearchTermMenu.setAttribute("hidden",false);
  2221.             overflow = true;
  2222.             mySearchTermBox.setAttribute("googlebaroverflow",true);
  2223.         }
  2224.         else {
  2225.             if (mySearchTermBox.getAttribute("googlebaroverflow")=="false") {
  2226.                 mySearchTermMenu.setAttribute("hidden",true);
  2227.             }
  2228.         }
  2229.     }
  2230.  
  2231.     if (myTerms.length > 0) {
  2232.       myGooglebarUtil.getElement("highlight-button").setAttribute("disabled", false);
  2233.     }
  2234. }
  2235.  
  2236. function googlebarCheckSearchbuttons()
  2237. {
  2238.     var critBox = myGooglebarUtil.getElement("googlebarCriteria");
  2239.     googlebarClearTerms();
  2240.     googlebarAddTerm(critBox.value);
  2241. }
  2242.  
  2243. function googlebarAvailableWidth()
  2244. {
  2245.     // This function returns the width which is available for the
  2246.     // search term buttons
  2247.     var width=0;
  2248.  
  2249.     width += myGooglebarUtil.getElement("google-menu").parentNode.boxObject.width;
  2250.     width -= myGooglebarUtil.getElement("google-menu").boxObject.width;
  2251.     width -= myGooglebarUtil.getElement("search-textbox").boxObject.width;
  2252.     width -= myGooglebarUtil.getElement("resize-splitter").boxObject.width;
  2253.     width -= myGooglebarUtil.getElement("googlebar-buttons").boxObject.width;
  2254.     return width;
  2255. }
  2256.  
  2257. function googlebarClearCrit()
  2258. {
  2259.     var critBox = myGooglebarUtil.getElement("googlebarCriteria");
  2260.     critBox.value = "";
  2261. }
  2262.  
  2263. function googlebarClearTerms()
  2264. {
  2265.     var termBox = myGooglebarUtil.getElement("googlebarSearchTerms");
  2266.     var termPopup = myGooglebarUtil.getElement("searchterms-popup");
  2267.     for (var numTerms = termBox.childNodes.length; numTerms > 0; numTerms--) {
  2268.         termBox.removeChild(termBox.childNodes[0]);
  2269.     }
  2270.     for (numTerms = termPopup.childNodes.length; numTerms > 0; numTerms--) {
  2271.         termPopup.removeChild(termPopup.childNodes[0]);
  2272.     }
  2273.     termBox.setAttribute("googlebaroverflow",false);
  2274. }
  2275.  
  2276. function googlebarUp(event)
  2277. {
  2278.     var mode;
  2279.     var win = window._content.document;
  2280.  
  2281.     var upContainer = myGooglebarUtil.getElement("up-dir-popup");
  2282.  
  2283.     if (upContainer && upContainer.childNodes.length > 0) {
  2284.         googlebarDoAction(upContainer.childNodes.item(0).getAttribute("label"), googlebarGetLocFromEvent(event));
  2285.     }
  2286. }
  2287.  
  2288. function googlebarHideItem(event)
  2289. {
  2290.     var item = event.target;
  2291.     var ggbItem = item.getAttribute("googlebaritem");
  2292.     var ggbButton, ggbMenuitem;
  2293.  
  2294.     ggbButton = myGooglebarUtil.getElement(ggbItem);    
  2295.     ggbButton.setAttribute("hidden", !item.getAttribute("checked"));
  2296.  
  2297.     if (hideMenuOption && ggbItem.indexOf("-separate") > 0) {
  2298.         ggbItem = ggbItem.replace("-separate", "");
  2299.         ggbMenuitem = myGooglebarUtil.getElement(ggbItem);
  2300.  
  2301.         if (ggbMenuitem) {
  2302.             ggbMenuitem.setAttribute("hidden", item.getAttribute("checked"));
  2303.         }
  2304.     }
  2305.  
  2306.     if (inPrefs) {
  2307.         googlebarGoPopupMenus(inPrefs);
  2308.     }
  2309.  
  2310.     updateSeparators();
  2311.     googlebarCheckSearchbuttons();
  2312. }
  2313.  
  2314. function googlebarOrdinalUpdater(event) {
  2315.     var lockOrdinals = event && event.target.getAttribute("checked") == "true";
  2316.     var lockButton = myGooglebarUtil.getElement("OrderLockButtonItem");
  2317.     
  2318.     if (lockButton) {
  2319.         lockButton.setAttribute("checked", lockOrdinals);
  2320.     }
  2321. }
  2322.  
  2323. function googlebarOrdinals(event, inPref)
  2324. {
  2325.     if (GB_PREF_OBJ.getBoolPref("lockOrdinals")) {
  2326.         lockOrdinalOrder();
  2327.     }
  2328.     else {
  2329.         unlockOrdinalOrder();
  2330.     }
  2331. }
  2332.  
  2333. function googlebarLabelUpdater(event) {
  2334.     var showLabels = event && event.target.getAttribute("checked") == "true";
  2335.     var showButton = myGooglebarUtil.getElement("LabelsButtonItem");
  2336.     
  2337.     if (showButton) {
  2338.         showButton.setAttribute("checked", showLabels);
  2339.     }
  2340. }
  2341.  
  2342. function googlebarLabels()
  2343. {
  2344.     if (GB_PREF_OBJ.getBoolPref("showLabels")) {
  2345.         googlebarLabelsOn();
  2346.     }
  2347.     else {
  2348.         googlebarLabelsOff();
  2349.     }
  2350. }
  2351.  
  2352. function googlebarLabelsOn()
  2353. {
  2354.     var container = myGooglebarUtil.getElement("googlebar-buttons");
  2355.     var containerButtons = container.getElementsByTagName("toolbarbutton");
  2356.  
  2357.     for (var i = 0; i < containerButtons.length; i++) {
  2358.         containerButtons[i].setAttribute("label", containerButtons[i].getAttribute("buttonlabel"));
  2359.         myGooglebarUtil.updateClass(containerButtons[i], 0, "button-labeled");
  2360.     }
  2361. }
  2362.  
  2363. function googlebarLabelsOff()
  2364. {
  2365.     var container = myGooglebarUtil.getElement("googlebar-buttons");
  2366.     var containerButtons = container.getElementsByTagName("toolbarbutton");
  2367.  
  2368.     for (var i = 0; i < containerButtons.length; i++) {
  2369.         containerButtons[i].removeAttribute("label");
  2370.         myGooglebarUtil.updateClass(containerButtons[i], 0, containerButtons[i].getAttribute("buttonclass"));
  2371.     }
  2372. }
  2373.  
  2374. function googlebarFindInPage(str, evt)
  2375. {
  2376.   /* This is shamelessly taken from Firebird findUtils.js */
  2377.   var found = false;
  2378.   var focusedWindow = document.commandDispatcher.focusedWindow;
  2379.   if (!focusedWindow || focusedWindow == window)
  2380.     focusedWindow = window._content;
  2381.   var findInst = getBrowser().webBrowserFind;
  2382.   var findInFrames = findInst.QueryInterface(Components.interfaces.nsIWebBrowserFindInFrames);
  2383.   findInFrames.rootSearchFrame = window._content;
  2384.   findInFrames.currentSearchFrame = focusedWindow;
  2385.  
  2386.   // setup the find instance
  2387.   findInst.searchString  = str;
  2388.  
  2389.   if(evt)
  2390. {
  2391.   // we hardcode the search options here with what seems to make most sense
  2392.   findInst.searchFrames = true;
  2393.   findInst.matchCase     = evt.ctrlKey;
  2394.   findInst.wrapFind      = true;
  2395.   findInst.entireWord = evt.altKey;
  2396.   findInst.findBackwards = evt.shiftKey;
  2397.   if(findInst.entireWord)
  2398.   findInst.searchString  = ' ' + str + ' ';
  2399. }
  2400.   found = findInst.findNext();
  2401.  
  2402.   if (!found) {
  2403.     alert('"' + str + '" ' + myGooglebarUtil.getElement("bundle_googlebar").getString("gb.notfound"));
  2404.   }
  2405. }
  2406.  
  2407. function updateUp()
  2408. {
  2409.     if (!window._content.document) {
  2410.         return;
  2411.     }
  2412.  
  2413.     var currentAddy = (queryStringOption) ? window._content.document.location.href.split("?")[0] : window._content.document.location.href;
  2414.     var arCurrentAddy = currentAddy.split("/");
  2415.     var tempNode = false;
  2416.     var curPath = false;
  2417.     var i;
  2418.  
  2419.     // Remove old instances
  2420.     var upContainer = myGooglebarUtil.getElement("up-dir-popup");
  2421.     for (i = upContainer.childNodes.length - 1; i >= 0; i--) {
  2422.         upContainer.removeChild(upContainer.childNodes.item(i));
  2423.     }
  2424.  
  2425.     // Add new instances
  2426.     for (i = arCurrentAddy.length - 1; i > 2; i--) {
  2427.  
  2428.         if (arCurrentAddy[i].length) {
  2429.             curPath = myGooglebarUtil.buildUrl(arCurrentAddy, i);
  2430.             tempNode = document.createElement("menuitem");
  2431.             tempNode.setAttribute("label", curPath);
  2432.             tempNode.setAttribute("class", "menuitem-all");
  2433.             tempNode.setAttribute("oncommand", "upGo(event, '" + curPath + "'); event.preventBubble();");
  2434.             tempNode.setAttribute("tooltiptext", curPath);
  2435.             upContainer.appendChild(tempNode);
  2436.         }
  2437.     }
  2438.  
  2439.     // If we are not at the default web host (www) then add that
  2440.     // host to the bottom of the list as Google toolbar does
  2441.     //
  2442.     // e.g. toolbar.google.com has www.google.com listed on "up" popup menu
  2443.  
  2444.     if (arCurrentAddy.length >= 3)
  2445.     {
  2446.         var currentHost = arCurrentAddy[2];
  2447.         var arHost = currentHost.split(".");
  2448.         var wwwHost;
  2449.  
  2450.         // Assumes somthing like this cs.insertschoolhere.edu, up converts to www.insertschoolhere.edu
  2451.         if (arHost.length == 3 && arHost[0] != "www") {
  2452.             wwwHost = arCurrentAddy[0] + "//www" + "."  + arHost[1] + "." + arHost[2] + "/";
  2453.             tempNode = document.createElement("menuitem");
  2454.             tempNode.setAttribute("label", wwwHost);
  2455.             tempNode.setAttribute("class", "menuitem-all");
  2456.             tempNode.setAttribute("oncommand", "upGo(event, '" + wwwHost + "'); event.preventBubble();");
  2457.             tempNode.setAttribute("tooltiptext", wwwHost);
  2458.             upContainer.appendChild(tempNode);
  2459.         }
  2460.         // Assumes somthing like this www.cs.insertschoolhere.edu, up converts to www.insertschoolhere.edu
  2461.         else if (arHost.length == 4 && arHost[0] == "www") {
  2462.             wwwHost = arCurrentAddy[0] + "//www" + "."  + arHost[2] + "." + arHost[3] + "/";
  2463.             tempNode = document.createElement("menuitem");
  2464.             tempNode.setAttribute("label", wwwHost);
  2465.             tempNode.setAttribute("class", "menuitem-all");
  2466.             tempNode.setAttribute("oncommand", "upGo(event, '" + wwwHost + "'); event.preventBubble();");
  2467.             tempNode.setAttribute("tooltiptext", wwwHost);
  2468.             upContainer.appendChild(tempNode);
  2469.         }
  2470.     }
  2471.  
  2472.     if (upContainer.childNodes.length > 0) {
  2473.         myGooglebarUtil.getElement("up-dir-button").setAttribute("disabled", false);
  2474.     }
  2475.     else {
  2476.         myGooglebarUtil.getElement("up-dir-button").setAttribute("disabled", true);
  2477.     }
  2478. }
  2479.  
  2480. function updateUniv()
  2481. {
  2482.     window._content.document.location = "http://www.google.com/options/universities.html";
  2483.     populateUniv = true;
  2484.     // setTimeout("reallyUpdateUniv()", 2000);
  2485. }
  2486.  
  2487. function reallyUpdateUniv()
  2488. {
  2489.     populateUniv = false;
  2490.     var univID = "univ-popup";
  2491.     var univMenu;
  2492.     var univPopup;
  2493.  
  2494.     // Remove old instances
  2495.     var univContainer = myGooglebarUtil.getElement(univID);
  2496.     for (var i = 3; i < univContainer.childNodes.length; i++) {
  2497.         univMenu = univContainer.childNodes.item(i);
  2498.         univPopup = univMenu.childNodes.item(0);
  2499.         for (var j = univPopup.childNodes.length - 1; j >= 0; j--) {
  2500.             univPopup.removeChild(univPopup.childNodes.item(j));
  2501.         }
  2502.     }
  2503.  
  2504.     var doc = window._content.document.documentElement;
  2505.     var aElems = doc.getElementsByTagName("A");
  2506.     var aData;
  2507.     var aHref;
  2508.     var startsWith;
  2509.     var tempNode;
  2510.  
  2511.     for (var k = 0; k < aElems.length; k++) {
  2512.         aHref = aElems[k].getAttribute("href");
  2513.         if (aHref) {
  2514.             if (/^\s*http:\/\/www.google.com\/univ\/(.*)/i.test(aHref)) {
  2515.                 aData = aElems[k].firstChild.data;
  2516.                 aData = aData.replace(/\s+/g, " ");
  2517.                 // aData = data.replace(/[\t\n\r ]+/g, " ");
  2518.                 startsWith = aData.substring(0, 1).toLowerCase();
  2519.  
  2520.                 univPopup = myGooglebarUtil.getElement(univID + "-" + startsWith);
  2521.  
  2522.                 if (univPopup) {
  2523.                     tempNode = document.createElement("menuitem");
  2524.                     tempNode.setAttribute("label", aData);
  2525.                     tempNode.setAttribute("class", "menuitem-all");
  2526.                     tempNode.setAttribute("oncommand", "setUniv('" + aHref + "', '" + aData + "'); event.preventBubble();");
  2527.                     tempNode.setAttribute("tooltiptext", aHref);
  2528.                     univPopup.appendChild(tempNode);
  2529.                 }
  2530.             }
  2531.         }
  2532.     }
  2533.     alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.univ.done"));
  2534. }
  2535.  
  2536. function setUniv(url, name)
  2537. {
  2538.     var univBtn;
  2539.  
  2540.     univBtn = myGooglebarUtil.getElement("univ-button");
  2541.     univBtn.removeAttribute("oncommand");
  2542.     univBtn.setAttribute("onclick", "if (event.button == 1) { univGo(event, '" + url + "') }");
  2543.     univBtn.setAttribute("oncommand", "univGo(event, '" + url + "');");
  2544.     univBtn.setAttribute("tooltiptext", myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.univ") + " - " + name);
  2545.  
  2546.     university = url;
  2547.     GB_PREF_OBJ.setCharPref("university", url);
  2548.     GB_PREF_OBJ.setCharPref("universityName", name);
  2549. }
  2550.  
  2551. function univGo(event)
  2552. {
  2553.     if (!university) {
  2554.         alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.button.univ.none"));
  2555.     }
  2556.     else {
  2557.         googlebarSearch(event, "university");
  2558.     }
  2559. }
  2560.  
  2561. function upGo(event, addy)
  2562. {
  2563.     googlebarDoAction(addy, googlebarGetLocFromEvent(event));
  2564. }
  2565.  
  2566. function googlebarCriteriaFocus()
  2567. {
  2568.     var critBox = myGooglebarUtil.getElement("googlebarCriteria");
  2569.     critBox.focus();
  2570. }
  2571.  
  2572. function getFocusedElement() {
  2573.   var ff = document.getElementsByAttribute("focused",true);
  2574.   return ff.length ? ff[0] : null;
  2575. }
  2576.  
  2577. // Stateful Show/Focus: interact with the GoogleBar given its current state
  2578. // using a single keyboard shortcut.  The possible state transitions are
  2579. //
  2580. //  - If the toolbar is hidden, toggle (show) it and focus on the criteria box
  2581. //
  2582. //  - If the criteria box is in focus and ...
  2583. //     - ... it has no text, fill in and select a default tooltip
  2584. //     - ... it has less than all of its text selected, select all its text
  2585. //     - ... it has all of its text selected, toggle (hide) the toolbar
  2586. //
  2587. //  - If the criteria box is blurred, then focus on it
  2588. //
  2589. // Before focus is given to the criteria box, the element with the current
  2590. // focus is saved.  When the toolbar is then later hidden, focus is restored
  2591. // to that saved element.
  2592.  
  2593. function googlebarStatefulShowFocus() {
  2594.  
  2595.   var googlebar = myGooglebarUtil.getElement( "googlebar" );
  2596.   var critBox = myGooglebarUtil.getElement( "googlebarCriteria" );
  2597.  
  2598.   if( googlebar.hidden ) {
  2599.  
  2600.     gStatefulPrevFocus = getFocusedElement();
  2601.     goToggleToolbar( "googlebar", "cmd_googlebarShowHide" );
  2602.     critBox.focus();
  2603.  
  2604.   } else if( critBox.getAttribute("focused") ) {
  2605.  
  2606.     if( critBox.inputField.textLength == 0 ) {
  2607.  
  2608.       critBox.value = "GoogleBar \"Enter your search text\"";
  2609.       critBox.inputField.select();
  2610.  
  2611.     } else {
  2612.  
  2613.       var curClickStart = critBox.inputField.selectionStart;
  2614.       var curClickEnd = critBox.inputField.selectionEnd;
  2615.       var curSelSize = curClickEnd - curClickStart;
  2616.  
  2617.       if( curSelSize < critBox.inputField.textLength ) {
  2618.  
  2619.     critBox.inputField.select();
  2620.  
  2621.       } else {
  2622.  
  2623.     if( gStatefulPrevFocus != null ) { gStatefulPrevFocus.focus(); }
  2624.     else { window.content.focus(); }
  2625.     goToggleToolbar( "googlebar", "cmd_googlebarShowHide" );
  2626.  
  2627.       }
  2628.     }
  2629.  
  2630.   } else {
  2631.  
  2632.     gStatefulPrevFocus = getFocusedElement();
  2633.     critBox.focus();
  2634.  
  2635.   }
  2636. }
  2637.  
  2638. function googlebarCriteriaSelect(event)
  2639. {
  2640.     if (!GB_PREF_OBJ.getBoolPref("autoselectoption")) { return; }
  2641.     
  2642.     var critBox = myGooglebarUtil.getElement("googlebarCriteria");
  2643.     var ePt = critBox.inputField.textLength;
  2644.     var curClickStart = critBox.inputField.selectionStart;
  2645.     var curClickEnd = critBox.inputField.selectionEnd;
  2646.     var curSelSize = curClickEnd - curClickStart;
  2647.  
  2648.     if (event && ePt > 0) {
  2649.         switch(event.type) {
  2650.  
  2651.         case "dblclick":
  2652.             if (!boolCritSelected) {
  2653.                 critBox.inputField.select();
  2654.                 boolCritSelected = true;
  2655.             }
  2656.             else {
  2657.                 critBox.inputField.setSelectionRange(curClickStart, curClickEnd);
  2658.                 boolCritSelected = false;
  2659.             }
  2660.             break;
  2661.  
  2662.         case "focus":
  2663.             if (critIgnoreFocus) {
  2664.                 critIgnoreFocus = false;
  2665.             }
  2666.             else {
  2667.                 if (boolCritSelected) {
  2668.                     if (hkeytgl) {
  2669.                         critBox.inputField.setSelectionRange(0, 0 );
  2670.                         boolCritSelected = false;
  2671.                     }
  2672.                     else {
  2673.                         critBox.inputField.select();
  2674.                     }
  2675.                 }
  2676.                 else {
  2677.                     critBox.inputField.select();
  2678.                     boolCritSelected = true;
  2679.                 }
  2680.             }
  2681.             break;
  2682.  
  2683.         case "mousedown":
  2684.             if (critBox.getAttribute("focused")) {
  2685.                 critIgnoreClick = true;
  2686.             }
  2687.             else {
  2688.                 critIgnoreFocus = true;
  2689.                 critIgnoreClick = false;
  2690.                 critBox.inputField.setSelectionRange(0, 0 );
  2691.                 boolCritSelected = true;
  2692.             }
  2693.             break;
  2694.  
  2695.         case "click":
  2696.             if (!critIgnoreClick && curSelSize == 0) {
  2697.                 critBox.inputField.select();
  2698.                 boolCritSelected = true;
  2699.             }
  2700.             break;
  2701.  
  2702.         default:
  2703.             break;
  2704.  
  2705.         }
  2706.     } // no event or text
  2707. }
  2708.  
  2709. function googlebarGoPopupMenus(inPrefs)
  2710. {
  2711.     var ggbPopupInUse = myGooglebarUtil.getElement("googlebar-buttons");
  2712.  
  2713.     googlebarSyncMainPopup("cust-menu", "CustomMenuItem");
  2714.     googlebarSyncMainPopup("gbsearch-separate", "SearchButtonItem");
  2715.     googlebarSyncMainPopup("site-separate", "SiteButtonItem");
  2716.     googlebarSyncMainPopup("lucky-separate", "LuckyButtonItem");
  2717.     googlebarSyncMainPopup("images-separate", "ImagesButtonItem");
  2718.     googlebarSyncMainPopup("groups-separate", "GroupsButtonItem");
  2719.     googlebarSyncMainPopup("directory-separate", "DirectoryButtonItem");
  2720.     googlebarSyncMainPopup("news-separate", "NewsButtonItem");
  2721.     googlebarSyncMainPopup("answers-separate", "AnswersButtonItem");
  2722.     googlebarSyncMainPopup("scholar-separate", "ScholarButtonItem");
  2723.     googlebarSyncMainPopup("gblogger-separate", "GbloggerButtonItem");
  2724.     googlebarSyncMainPopup("gb-prefill-separate", "gb-prefillButtonItem");
  2725.     
  2726.     googlebarSyncMainPopup("gb-options-separate", "OptionsButtonItem");
  2727.     googlebarSyncMainPopup("catalog-separate", "CatalogButtonItem");
  2728.     googlebarSyncMainPopup("froogle-separate", "FroogleButtonItem");
  2729.     googlebarSyncMainPopup("stocks-separate", "StocksButtonItem");
  2730.     googlebarSyncMainPopup("unclesam-separate", "UnclesamButtonItem");
  2731.     googlebarSyncMainPopup("viewer-separate", "ViewerButtonItem");
  2732.     googlebarSyncMainPopup("webquotes-separate", "WebquotesButtonItem");
  2733.     googlebarSyncMainPopup("dictionary-separate", "DictionaryButtonItem");
  2734.     googlebarSyncMainPopup("glossary-separate", "GlossaryButtonItem");
  2735.     googlebarSyncMainPopup("nocalc-separate", "NocalcButtonItem");
  2736.     googlebarSyncMainPopup("gb-mycountry-separate", "GbmycountryButtonItem");
  2737.     googlebarSyncMainPopup("gb-mylocal-separate", "GbmylocalButtonItem");
  2738.     googlebarSyncMainPopup("bsd-separate", "BsdButtonItem");
  2739.     googlebarSyncMainPopup("linux-separate", "LinuxButtonItem");
  2740.     googlebarSyncMainPopup("mac-separate", "MacButtonItem");
  2741.     googlebarSyncMainPopup("microsoft-separate", "MicrosoftButtonItem");
  2742.  
  2743.     googlebarSyncMainPopup("cached-separate", "CachedButtonItem");
  2744.     googlebarSyncMainPopup("similar-separate", "SimilarButtonItem");
  2745.     googlebarSyncMainPopup("backwards-separate", "BackwardsButtonItem");
  2746.     googlebarSyncMainPopup("translate-separate", "TranslateButtonItem");
  2747.  
  2748.     googlebarSyncMainPopup("spec-menu", "SpecButtonItem");
  2749.     googlebarSyncMainPopup("comp-menu", "CompButtonItem");
  2750.     googlebarSyncMainPopup("univ-button", "UnivButtonItem");
  2751.     googlebarSyncMainPopup("extras-box", "ExtrasButtonItem");
  2752.     googlebarSyncMainPopup("info-menu", "InfoButtonItem");
  2753.     googlebarSyncMainPopup("up-dir-button", "UpDirButtonItem");
  2754.     googlebarSyncMainPopup("nav-box", "NavButtonItem");
  2755.     googlebarSyncMainPopup("highlightplus-button", "HighlightPlusButtonItem");
  2756.     googlebarSyncMainPopup("highlight-button", "HighlightButtonItem");
  2757.     googlebarSyncMainPopup("googlebarSearchTerms", "SearchTermsButtonItem");
  2758.  
  2759.     if (inPrefs) { return; }
  2760.  
  2761.     var element = myGooglebarUtil.getElement("OrderLockButtonItem");
  2762.     if (element.getAttribute("checked") == "true") {
  2763.         lockOrdinalOrder();
  2764.     }
  2765.     else {
  2766.         unlockOrdinalOrder();
  2767.     }
  2768. }
  2769.  
  2770. function googlebarSyncMainPopup(src, dest)
  2771. {
  2772.     var ggbButtonState = myGooglebarUtil.getElement(src);
  2773.     var ggbPopupChecked = myGooglebarUtil.getElement(dest);
  2774.  
  2775.     ggbPopupChecked.setAttribute("checked", !(ggbButtonState.getAttribute("hidden") == "true"));
  2776.  
  2777.     if (hideMenuOption && src.indexOf("-separate") > 0) {
  2778.         var ggbItem = src.replace("-separate", "");
  2779.         var ggbMenuitem = myGooglebarUtil.getElement(ggbItem);
  2780.  
  2781.         if (ggbMenuitem) {
  2782.             ggbMenuitem.setAttribute("hidden", !(ggbButtonState.getAttribute("hidden") == "true"));
  2783.         }
  2784.     }
  2785. }
  2786.  
  2787. function googlebarSyncMenuButton(ggbButton, ggbOption)
  2788. {
  2789.     // If there was a previous search selected for the
  2790.     // menu button and the preference is set to save
  2791.     // these settings then attempt to restore the
  2792.     // selection, if possible, otherwise just ignore it
  2793.  
  2794.     if (!saveLastOption) {
  2795.         return;
  2796.     }
  2797.  
  2798.     var optionValue;
  2799.  
  2800.     try {
  2801.         optionValue = GB_PREF_OBJ.getCharPref(ggbOption);
  2802.     }
  2803.     catch(e) { myGooglebarUtil.logMessage(  "\n" + e + "\n" );
  2804.         GB_PREF_OBJ.setCharPref(ggbOption, "");
  2805.         optionValue = "";
  2806.     }
  2807.  
  2808.     var menuButton = myGooglebarUtil.getElement(ggbButton);
  2809.     var separateButton = myGooglebarUtil.getElement(optionValue + "-separate");
  2810.  
  2811.     if (!menuButton || !separateButton) {
  2812.         return;
  2813.     }
  2814.  
  2815.     menuButton.removeAttribute("oncommand");
  2816.     menuButton.setAttribute("oncommand", separateButton.getAttribute("oncommand"));
  2817.  
  2818.     menuButton.setAttribute("buttonclass", separateButton.getAttribute("buttonclass"));
  2819.     menuButton.setAttribute("class", separateButton.getAttribute("class"));
  2820.  
  2821.     menuButton.setAttribute("buttonlabel", separateButton.getAttribute("buttonlabel"));
  2822.     menuButton.setAttribute("tooltiptext", separateButton.getAttribute("tooltiptext"));
  2823.  
  2824.     if (separateButton.getAttribute("label")) {
  2825.         menuButton.setAttribute("label", separateButton.getAttribute("label"));
  2826.     }
  2827. }
  2828.  
  2829. function googlebarCriteriaTooltip()
  2830. {
  2831.     var critBox = myGooglebarUtil.getElement("googlebarCriteria");
  2832.  
  2833.     if (critBox.value) {
  2834.         critBox.tooltipText = critBox.value;
  2835.     }
  2836.     else {
  2837.         critBox.tooltipText = critBox.statusText;
  2838.     }
  2839. }
  2840.  
  2841. function srchFlipflop()
  2842. {
  2843.     var ggbsrchterms = myGooglebarUtil.getElement("googlebarSearchTerms");
  2844.     var searchTermMenu = myGooglebarUtil.getElement("searchterms-menu");
  2845.     ggbsrchterms.setAttribute("hidden", !ggbsrchterms.hidden );
  2846.  
  2847.     // when we are overflowing, set the hidden status of the overflow
  2848.     // menu accordingly
  2849.     if (ggbsrchterms.getAttribute("googlebaroverflow")=="true") {
  2850.         searchTermMenu.setAttribute("hidden", ggbsrchterms.hidden );
  2851.     }
  2852.  
  2853.     // when the search buttons were unhidden, we have to check
  2854.     // if they fit
  2855.     if (!ggbsrchterms.hidden) {
  2856.         googlebarCheckSearchbuttons();
  2857.     }
  2858.     return true;
  2859. }
  2860.  
  2861. function setGoogleContextMenu(inPrefs)
  2862. {    
  2863.     var cntxtmnu = myGooglebarUtil.getElement('context-googlebar-doc-items');
  2864.     var cntxtmnu_sep = myGooglebarUtil.getElement('context-sep-google');
  2865.     var cntxtmnuopt;
  2866.     
  2867.     if (inPrefs) {
  2868.         cntxtmnuopt = !myGooglebarUtil.getElement('contextmenuoption').checked;
  2869.     }
  2870.     else {
  2871.         cntxtmnuopt = !GB_PREF_OBJ.getBoolPref("contextmenuoption");
  2872.     }
  2873.  
  2874.        cntxtmnu.setAttribute('hidden', cntxtmnuopt);
  2875.     cntxtmnu_sep.setAttribute('hidden', cntxtmnuopt);
  2876. }
  2877.  
  2878. function cntrySfxsInit()
  2879. {
  2880.     for (var i = 0; myGooglebarUtil.getElement("bundle_googlebar").getString("gb.country." + i) != "endoflist"; i++) {
  2881.         cntrySfxs[i] = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.country." + i);
  2882.     }
  2883. }
  2884.  
  2885. function mycntrySfxsInit()
  2886. {
  2887.     for (var i = 0; myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mycountry." + i) != "endoflist"; i++) {
  2888.         mycntrySfxs[i] = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mycountry." + i);
  2889.     }
  2890. }
  2891.  
  2892. function mylangSfxsInit()
  2893. {
  2894.     for (var i = 0; myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mylang." + i) != "endoflist"; i++) {
  2895.         mylangSfxs[i] = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.mylang." + i);
  2896.     }
  2897. }
  2898.  
  2899.  
  2900. function cntryNewsSfxsInit()
  2901. {
  2902.     for (var i = 0; myGooglebarUtil.getElement("bundle_googlebar").getString("gb.news.country." + i) != "endoflist"; i++) {
  2903.         cntryNewsSfxs[i] = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.news.country." + i);
  2904.         cntryNewsSites[i] = myGooglebarUtil.getElement("bundle_googlebar").getString("gb.news.country.site." + i);
  2905.     }
  2906. }
  2907.  
  2908. function selectGgbCountry(cntry)
  2909. {
  2910.     if (cntry) {
  2911.         GB_PREF_OBJ.setIntPref("country2Search", cntry);
  2912.         cntry2SrchIx = cntry;
  2913.         cntry2Srch = cntrySfxs[cntry2SrchIx];
  2914.     }
  2915.     else {
  2916.         alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.country.none"));
  2917.     }
  2918. }
  2919.  
  2920. function selectGgbCountryNews(cntry)
  2921. {
  2922.     if (cntry) {
  2923.         GB_PREF_OBJ.setIntPref("countryNews2Search", cntry);
  2924.         cntryNews2SrchIx = cntry;
  2925.         cntryNews2Srch = cntryNewsSfxs[cntryNews2SrchIx];
  2926.         cntryNewsSite = cntryNewsSites[cntryNews2SrchIx];
  2927.     }
  2928.     else {
  2929.         alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.news.country.none"));
  2930.     }
  2931. }
  2932.  
  2933. function selectGgbMyCountry(cntry)
  2934. {
  2935.     if (cntry) {
  2936.         GB_PREF_OBJ.setIntPref("mycountry2Search", cntry);
  2937.         mycntry2SrchIx = cntry;
  2938.         mycntry2Srch = mycntrySfxs[mycntry2SrchIx];
  2939.     }
  2940.     else {
  2941.         alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.country.none"));
  2942.     }
  2943. }
  2944.  
  2945. function selectGgbMyLang(cntry)
  2946. {
  2947.     if (cntry) {
  2948.         GB_PREF_OBJ.setIntPref("mylang2Search", cntry);
  2949.         mylang2SrchIx = cntry;
  2950.         mylang2Srch = mylangSfxs[mylang2SrchIx];
  2951.     }
  2952.     else {
  2953.         alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.lang.none"));
  2954.     }
  2955. }
  2956.  
  2957. function setMaxHistCnt(cnt)
  2958. {
  2959.     if (cnt) {
  2960.         GB_PREF_OBJ.setIntPref("maxHistCnt", cnt);
  2961.     }
  2962.     else {
  2963.         alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.error.max_hist"));
  2964.         GB_PREF_OBJ.setIntPref("maxHistCnt", 10);
  2965.     }
  2966.     maxHistCnt = GB_PREF_OBJ.getIntPref("maxHistCnt");
  2967. }
  2968.  
  2969. function setResultLimit(cnt)
  2970. {
  2971.     if (cnt) {
  2972.         GB_PREF_OBJ.setIntPref("resultLimit", cnt);
  2973.     }
  2974.     else {
  2975.         alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.error.result_limit"));
  2976.         GB_PREF_OBJ.setIntPref("resultLimit", -1);
  2977.     }
  2978.     resultLimit = GB_PREF_OBJ.getIntPref("resultLimit");
  2979. }
  2980.  
  2981. function googlebarOpenPrefs()
  2982. {
  2983.     if (myGooglebarUtil.isInFirefox()) {
  2984.         window.openDialog('chrome://googlebar/content/googlebarPrefDialog.xul', 'Googlebar Options', 'chrome');
  2985.     }
  2986.     else {
  2987.         goPreferences('googlebarItem', 'chrome://googlebar/content/pref/pref-googlebar1.xul', 'googlebarItem');
  2988.     }
  2989. }
  2990.  
  2991. function googlebarOpenGooglePrefs()
  2992. {
  2993.     window._content.document.location = 'http://www.google.' + cntry2Srch + '/preferences';
  2994. }
  2995.  
  2996. function googlebarUpdateParent(event)
  2997. {
  2998.     if (!saveLastOption) {
  2999.         return;
  3000.     }
  3001.  
  3002.     var menuButton = event.target.parentNode.parentNode;
  3003.     var separateButton = myGooglebarUtil.getElement(event.target.getAttribute("id") + "-separate");
  3004.  
  3005.     menuButton.removeAttribute("oncommand");
  3006.     menuButton.setAttribute("oncommand", separateButton.getAttribute("oncommand"));
  3007.  
  3008.     menuButton.setAttribute("buttonclass", separateButton.getAttribute("buttonclass"));
  3009.     menuButton.setAttribute("class", separateButton.getAttribute("class"));
  3010.     
  3011.     menuButton.setAttribute("buttonlabel", separateButton.getAttribute("buttonlabel"));
  3012.     menuButton.setAttribute("tooltiptext", separateButton.getAttribute("tooltiptext"));
  3013.  
  3014.     if (separateButton.getAttribute("label")) {
  3015.         menuButton.setAttribute("label", separateButton.getAttribute("label"));
  3016.     }
  3017.  
  3018.     if (menuButton.getAttribute("id") == "comp-menu") {
  3019.         GB_PREF_OBJ.setCharPref("lastCompSearch", event.target.getAttribute("id"));
  3020.     }
  3021.     else if (menuButton.getAttribute("id") == "cust-menu") {
  3022.         GB_PREF_OBJ.setCharPref("lastCustSearch", event.target.getAttribute("id"));
  3023.     }
  3024.     else if (menuButton.getAttribute("id") == "info-menu") {
  3025.         GB_PREF_OBJ.setCharPref("lastInfoSearch", event.target.getAttribute("id"));
  3026.     }
  3027.     else if (menuButton.getAttribute("id") == "spec-menu") {
  3028.         GB_PREF_OBJ.setCharPref("lastSpecSearch", event.target.getAttribute("id"));
  3029.     }
  3030.     else {
  3031.         alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.googlebarUpdateParent.1") + menuButton.getAttribute("id")); 
  3032.     }
  3033. }
  3034.  
  3035. function googlebarResetParents(event)
  3036. {
  3037.     if (event.target.checked)
  3038.         return;
  3039.  
  3040.     googlebarResetParent(myGooglebarUtil.getElement('comp-menu'));
  3041.     googlebarResetParent(myGooglebarUtil.getElement('cust-menu'));
  3042.     googlebarResetParent(myGooglebarUtil.getElement('info-menu'));
  3043.     googlebarResetParent(myGooglebarUtil.getElement('spec-menu'));
  3044. }
  3045.  
  3046. function googlebarResetParent(menuButton)
  3047. {
  3048.     menuButton.removeAttribute("oncommand");
  3049.     menuButton.setAttribute("oncommand", "googlebarShowPopup(event)");
  3050.  
  3051.     menuButton.setAttribute("buttonclass", menuButton.getAttribute('id'));
  3052.     menuButton.setAttribute("class", menuButton.getAttribute('id') + " dragbordernone");
  3053.  
  3054.     menuButton.setAttribute("buttonlabel", menuButton.getAttribute('originallabel'));
  3055.     menuButton.setAttribute("tooltiptext", menuButton.getAttribute('originaltooltip'));
  3056.     
  3057.     if (menuButton.getAttribute("label")) {
  3058.         menuButton.setAttribute("label", menuButton.getAttribute('originallabel'));
  3059.     }
  3060. }
  3061.  
  3062. function googlebarShowPopup(event)
  3063. {
  3064.     if ((event.target.getAttribute("type") == "menu" || event.target.getAttribute("type") == "menu-button") && event.target.firstChild)
  3065.     {
  3066.       event.target.firstChild.showPopup();
  3067.     }
  3068. }
  3069.  
  3070. function googlebarUpdateNewWindow()
  3071. {
  3072.     // Only need to update from another window once
  3073.     // Get out of here if that has already happened
  3074.     if (openerUpdated)
  3075.         return;
  3076.         
  3077.     // This method is used to update the current search terms 
  3078.     // from another window. This should happen when
  3079.     // 1. a new window is opened for the first time called from googlebarDisplayCheck()
  3080.     // 2. a google search result
  3081.  
  3082.     var otherCriteria = null;
  3083.     var otherHighlight = null;
  3084.     var thisCriteria = myGooglebarUtil.getElement("googlebarCriteria");
  3085.  
  3086.     // If this window was opened from another window, just use
  3087.     // the criteria from the opener
  3088.     if (window.opener) {
  3089.         otherCriteria = window.opener.document.getElementById("googlebarCriteria");
  3090.         otherHighlight = window.opener.document.getElementById("highlight-button");
  3091.       
  3092.         if (otherCriteria){
  3093.             thisCriteria.value = otherCriteria.value;
  3094.             openerUpdated = true;
  3095.             myGooglebarUtil.logMessage('Updated criteria from window opener');
  3096.         }
  3097.     }
  3098.     else {
  3099.         // window had not opener, so get the criteria from somewhere else
  3100.         var openwindows = GB_WINDOW_SVC.getEnumerator(null);
  3101.     
  3102.         // check all open windows for googlebarCriteria
  3103.         // this will always get the search terms of the last window
  3104.         // in the list, this might not be the last window which was
  3105.         // selected, so this might not always give the expected result
  3106.         while (openwindows.hasMoreElements()) {
  3107.             var win = openwindows.getNext();
  3108.  
  3109.             if (win != window) {
  3110.                 otherCriteria = win.document.getElementById("googlebarCriteria");
  3111.                 otherHighlight = win.document.getElementById("highlight-button");
  3112.         
  3113.                 if (otherCriteria) {
  3114.                     // Does this work?
  3115.                      thisCriteria.value = otherCriteria.value;
  3116.                     openerUpdated = true;
  3117.                     myGooglebarUtil.logMessage('Updated criteria from another window containing a googlebar');
  3118.                     break;
  3119.                 }
  3120.             }
  3121.         }
  3122.     }
  3123.  
  3124.     if (otherHighlight && otherHighlight.getAttribute("activated") == "true") {
  3125.         myGooglebarHighlight.highLightInPage("on");
  3126.     }
  3127. }
  3128.  
  3129. function check4NewInstall() {
  3130.  
  3131. if(gbCheck4BrowserWindows()){
  3132. // Look for a zero byte file - googlebarIsNew
  3133. // This file is only needed if someone changes or adds prefs
  3134. // It puts the responsibility on the user for prefs that point to old
  3135. // meanings. Unless someone want to make a versioned table of prefs :)
  3136.  
  3137. const kDirServiceCID = Components.ID("{f00152d0-b40b-11d3-8c9c-000064657374}");
  3138. const nsIProperties = Components.interfaces.nsIProperties;
  3139. const nsIFileIID = Components.ID("{c8c0a080-0868-11d3-915f-d9d889d48e3c}");
  3140.  
  3141. var cTyp = retv = 0;
  3142. var dSrv = Components.classes['@mozilla.org/file/directory_service;1'].createInstance();
  3143. dSrv = dSrv.QueryInterface(Components.interfaces.nsIProperties);
  3144.  
  3145.  
  3146.     var dSrvI = dSrv.get("AChrom", Components.interfaces.nsIFile);
  3147.     
  3148.     dSrvI.append("googlebar");
  3149.     dSrvI.append("content");
  3150.     dSrvI.append("googlebarIsNew");
  3151.     retv=dSrvI.exists();
  3152.     if(retv) {
  3153.           cTyp ="AChrom";
  3154.         } 
  3155.         else {
  3156.           dSrvI = dSrv.get("UChrm", Components.interfaces.nsIFile);
  3157.           dSrvI.append("googlebar");
  3158.           dSrvI.append("content");
  3159.           dSrvI.append("googlebarIsNew");
  3160.           retv=dSrvI.exists();
  3161.           if(retv)
  3162.             cTyp ="UChrm";
  3163.         }
  3164.  
  3165.     if(!cTyp){
  3166.         // myGooglebarUtil.logMessage("googlebarIsNew NOT Found in any chrome location\n");
  3167.         // Here we can set a pref that is really a flag
  3168.         // that then works for every tab and window.
  3169.         // that we have checked for any new installation.
  3170.         return;
  3171.         }
  3172.         
  3173.     // returns our c:\\windows\stuff as file:///c:/windows
  3174.     // not used yet, but it may be later
  3175.     // var thisUri = getFileUri(dSrvI);
  3176.  
  3177. if(cTyp=="UChrm"){
  3178.     myGooglebarUtil.logMessage("Found googlebarIsNew in user profile\n");
  3179.         // Tell the user to check their preferences,
  3180.         // because they are probably there but have changed meaning.
  3181.     if(confirm(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.check4NewInstall.1") )) {
  3182.         googlebarOpenPrefs();
  3183.         // delete the triggerfile
  3184.         dSrvI.remove(true) ;
  3185.     }
  3186.     else
  3187.     if(!confirm(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.check4NewInstall.2") )) {
  3188.         // delet the triggerfile
  3189.         dSrvI.remove(true) ;
  3190.         }
  3191.  
  3192.     } //if(cTyp=="UChrm")
  3193.  
  3194. if(cTyp=="AChrom"){
  3195.     myGooglebarUtil.logMessage("Found googlebarIsNew in system profile\n");
  3196.     // Tell the user to check their preferences,
  3197.     // because they are probably there but have changed meaning.
  3198.         if(confirm(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.check4NewInstall.1") )) {
  3199.             googlebarOpenPrefs();
  3200.             // delete the triggerfile
  3201.             dSrvI.remove(true) ;
  3202.     }
  3203.     else
  3204.     if(!confirm(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.check4NewInstall.2") )) {
  3205.         // delet the triggerfile
  3206.         dSrvI.remove(true) ;
  3207.         }
  3208.  
  3209.     }//if(cTyp=="AChrom")
  3210.  
  3211.   }// if we have a browser window...
  3212.  
  3213. }
  3214.  
  3215.  
  3216. function getFileUri( fpath ){
  3217. const nsIFileIID = Components.ID("{c8c0a080-0868-11d3-915f-d9d889d48e3c}");
  3218. var ios = Components.classes["@mozilla.org/network/io-service;1"]
  3219.         .getService(Components.interfaces.nsIIOService);
  3220. var newUri;
  3221.  
  3222.     // Interface change - ns7 (mozilla 1.0) needs nsIIOService
  3223.     // latter (mozilla 1.2) needs nsIFileProtocolHandler
  3224.     if(Components.interfaces.nsIFileProtocolHandler){
  3225.       var fileHandler =
  3226.       ios.getProtocolHandler("file")
  3227.       .QueryInterface(Components.interfaces.nsIFileProtocolHandler);  
  3228.       newUri = fileHandler.getURLSpecFromFile(fpath);
  3229.     } else {
  3230.       newUri = ios.getURLSpecFromFile(fpath);
  3231.     }
  3232.     
  3233. return newUri;
  3234. }
  3235.  
  3236. function gbCheck4BrowserWindows() {
  3237. // Quicklaunch seems to be a full browser window.
  3238.  
  3239.     if(GB_WINDOW_SVC.getMostRecentWindow("navigator:browser"))
  3240.     {
  3241.       if ("arguments" in window && window.arguments.length > 1 && window.arguments[1])
  3242.       {
  3243.         if (window.arguments[1].indexOf("charset=") != -1)
  3244.         {
  3245.           var arrayArgComponents = window.arguments[1].split("=");
  3246.           if (arrayArgComponents)
  3247.           {
  3248.             getMarkupDocumentViewer().defaultCharacterSet = arrayArgComponents[1];
  3249.           }
  3250.         }
  3251.         else
  3252.         if (window.arguments[1].indexOf("turbo=yes") != -1)
  3253.         {
  3254.           var gb_turboMode = true;
  3255.           return false ;
  3256.         }
  3257.  
  3258.     } // got a browser window besides quicklaunch
  3259.        return true ;
  3260.        
  3261.   } // no browsers
  3262.   return false;
  3263. }
  3264.  
  3265.  
  3266. function googlebarIsUnHiding(){
  3267.     var googlebar = myGooglebarUtil.getElement( "googlebar" );
  3268.     var currCrit = myGooglebarUtil.getElement("googlebarCriteria").value ;
  3269.     
  3270.     // If you have some text in the criteria box, updating searchword buttons
  3271.     // on reappearance is unsightly. The buttons adjust one character at a time.
  3272.  
  3273.     if(!googlebar.getAttribute("hidden") || googlebar.getAttribute("hidden") == "false")
  3274.         return;
  3275.  
  3276.     googlebarClearCrit();
  3277.     googlebarClearTerms();
  3278.     goToggleToolbar("googlebar","cmd_googlebarShowHide");
  3279.     setTimeout("myGooglebarUtil.getElement('googlebarCriteria').focus()", 100);
  3280.  
  3281.     // let's just blank it out... for now.
  3282.     currCrit = "";
  3283.     myGooglebarUtil.getElement("googlebarCriteria").value = currCrit;
  3284.     googlebarAddTerm(currCrit);
  3285. }
  3286.  
  3287. function googlebarIsHiding(){
  3288.     var googlebar = myGooglebarUtil.getElement("googlebar");
  3289.  
  3290.     if(googlebar.getAttribute("hidden") && googlebar.getAttribute("hidden") == "true")
  3291.         return;
  3292.  
  3293.     goToggleToolbar('googlebar','cmd_googlebarShowHide');
  3294.     setTimeout("window.document.getElementById('urlbar').focus()", 0);
  3295. }
  3296.  
  3297. function gbDoNonSearch(event, searchType, searchParams) {
  3298. // a place to do non Google searches explicitly
  3299. // return true if we find anything we can handle, whether we actually do anything
  3300. // with it is not relevant, just whether we should keep going through the main search
  3301. // processing
  3302.     
  3303.     if( searchType == 'gb-prefill' ) {
  3304.         if(myGooglebarUtil.isInFirefox()) {
  3305.             alert(myGooglebarUtil.getElement("bundle_googlebar").getString("gb.gbDoNonSearch.1"));        
  3306.         }
  3307.  
  3308.         var gbformsArray = content.document.forms;
  3309.         if ( !gbformsArray ) {
  3310.             return true ;
  3311.         }
  3312.         
  3313.         if (event.button == 1) {
  3314.         var gbwallet = Components.classes["@mozilla.org/wallet/wallet-service;1"].getService(Components.interfaces.nsIWalletService);
  3315.             gbwallet.WALLET_RequestToCapture( window._content );
  3316.         }
  3317.  
  3318.         else {
  3319.         if( event.ctrlKey || event.shiftKey || event.altKey ) {
  3320.             formPrefill();
  3321.             // any modifier key bring up the forms dialog if an unknown form,
  3322.             // known forms it will fill in if you told it to do so previously
  3323.             // do we want to touch passwords and the security issues.
  3324.         }
  3325.         else
  3326.         var walletService = Components.classes["@mozilla.org/wallet/wallet-service;1"].getService(Components.interfaces.nsIWalletService);
  3327.             try { walletService.WALLET_Prefill(true, window._content); }
  3328.             catch(e) { } 
  3329.         }
  3330.  
  3331.         return true;
  3332.     }
  3333.  
  3334.     return false; // we found nothing to handle here, keep going with main googlebarSearch
  3335. }
  3336.  
  3337. function gbLook4URL(event, searchType, searchParams)
  3338. {
  3339.     var criteria = myGooglebarUtil.getElement("googlebarCriteria");
  3340.     var testIndx;
  3341.     var tempval  = criteria.value;
  3342.  
  3343.  
  3344.     try { testIndx = tempval.search(/^(http|https|ftp|file|irc|mailto|news|nntp):/i); }
  3345.         catch(e)
  3346.             {
  3347.             testIndx = -1;
  3348.         } // nothing
  3349.  
  3350.     if(testIndx != -1)
  3351.         return 1;
  3352.     else
  3353.     try { testIndx = tempval.search(/^(www\.)/i); }
  3354.         catch(e)
  3355.             { /* XXX replace the prefix to http://  */
  3356.             testIndx = -1;
  3357.            } 
  3358.         
  3359.     if(testIndx != -1) {
  3360.         var newval = "http://" + criteria.value;
  3361.         criteria.value = newval;
  3362.         return 1;
  3363.     }
  3364.     else
  3365.         return 0;
  3366.         // we didn't find it, or there was a general error
  3367.         
  3368. }
  3369.  
  3370. function gbprompt(msg, initial, parent, title)
  3371. {     
  3372.      var PROMPT_CTRID = "@mozilla.org/embedcomp/prompt-service;1";
  3373.      var nsIPromptService = Components.interfaces.nsIPromptService;
  3374.      var ps = Components.classes[PROMPT_CTRID].getService(nsIPromptService);
  3375.      if (!parent)
  3376.          parent = window;
  3377.      if (!title)
  3378.          title = MSG_PROMPT; // probably just in seamonkey
  3379.      rv = { value: initial };
  3380.  
  3381.      if (!ps.prompt (parent, title, msg, rv, null, {value: null}))
  3382.          return null;
  3383.  
  3384.      return rv.value;
  3385. }
  3386.  
  3387. function googlebarOrderMenu(menuName, startIndex) {
  3388.     if (!startIndex)
  3389.         startIndex = 0;
  3390.  
  3391.     var i, j;
  3392.     var menuElement = myGooglebarUtil.getElement(menuName);
  3393.     var unorderedItems = menuElement.getElementsByTagName("menuitem");
  3394.     
  3395.     var orderedItems = new Array(unorderedItems.length - startIndex);
  3396.     for (i = startIndex; i < unorderedItems.length; i++) {
  3397.         orderedItems[i - startIndex] = unorderedItems[i];
  3398.     }
  3399.  
  3400.     var tempItem;
  3401.     
  3402.     // Quick bubble sort - list is short so performance doesn't matter much
  3403.     for (i = orderedItems.length - 1; i > 0; i--) {        
  3404.         for (j = 0; j < i; j++) {
  3405.             if (orderedItems[j].getAttribute("label") > orderedItems[j + 1].getAttribute("label")) {
  3406.                 tempItem = orderedItems[j + 1];
  3407.                 orderedItems[j + 1] = orderedItems[j];
  3408.                 orderedItems[j] = tempItem;
  3409.             }
  3410.         }
  3411.     }
  3412.     
  3413.     for (i = 0; i < orderedItems.length; i++) {
  3414.         orderedItems[i].setAttribute("ordinal", i + startIndex);
  3415.     }
  3416.     
  3417.     menuElement.setAttribute("hidden", "true");
  3418.     menuElement.setAttribute("hidden", "false");
  3419. }
  3420.  
  3421. function googlebarGetCustomList()
  3422. {
  3423.     var customList = new Array();
  3424.     
  3425.     var custPopup = myGooglebarUtil.getElement('cust-popup');
  3426.     for (var i = custPopup.childNodes.length - 1; i >= 0; i--) {
  3427.         customList.push(custPopup.childNodes[i].getAttribute('id'));
  3428.     }
  3429.     
  3430.     return customList;
  3431. }
  3432.  
  3433. function googlebarUpdateCustomList(customList)
  3434. {
  3435.     if (!customList)
  3436.         customList = [];
  3437.  
  3438.     var custPopup = myGooglebarUtil.getElement('cust-popup');
  3439.     var i;
  3440.     
  3441.     for (i = custPopup.childNodes.length - 1; i >= 0; i--) {
  3442.         custPopup.removeChild(custPopup.childNodes[i]);
  3443.     }
  3444.  
  3445.     var customString = "";    
  3446.     for (i = 0; i < customList.length; i++) {
  3447.         var custChild = myGooglebarUtil.getElement(customList[i]).cloneNode(false);
  3448.         custPopup.appendChild(custChild);
  3449.         
  3450.         if (i > 0) {
  3451.             customString += sep;
  3452.         }
  3453.         customString += custChild.getAttribute('id');
  3454.     }
  3455.     
  3456.     var string = new GB_STRING_CONSTRUCTOR;
  3457.     string.data = customString;
  3458.     GB_PREF_OBJ.setComplexValue("customList", GB_STRING_FLAG, string);
  3459. }
  3460.  
  3461. ///////////////////////////////////////////////////////////////////////////////
  3462. ////////////////////////////// Experimental ///////////////////////////////////
  3463.  
  3464. function googlebarRemoveListener() {
  3465.     window.getBrowser().removeProgressListener(myGooglebarLocListener);
  3466. }
  3467.  
  3468. function googlebarSuggest(searchString)
  3469. {
  3470.     if (!GB_PREF_OBJ.getBoolPref("googleSuggest"))
  3471.         return;
  3472.     if (myGooglebarUtil.trimString(searchString) == "")
  3473.         return;
  3474.     
  3475.     var searchURL = 'http://www.google.com/complete/search?hl=en&js=true&qu=' + searchString;
  3476.     myGooglebarUtil.getElement('googleSuggestFrame').setAttribute('src', searchURL);
  3477.     
  3478.     setTimeout("googlebarUpdateSuggest()", 500);
  3479. }
  3480.  
  3481. function googlebarUpdateSuggest()
  3482. {
  3483.     try {
  3484.         var html = myGooglebarUtil.getElement('googleSuggestFrame').contentDocument;
  3485.         var text = html.getElementsByTagName('BODY')[0].firstChild.nodeValue;
  3486.         var cmd = text.replace(/\s*sendRPCDone\(frameElement,\s*/, 'googlebarDisplaySuggest(');
  3487.         eval(cmd);
  3488.     }
  3489.     catch (e) {
  3490.         // Do something here, at some point
  3491.     }
  3492. }
  3493.  
  3494. function googlebarSearchSuggest(event, searchString)
  3495. {
  3496.     myGooglebarUtil.getElement("googlebarCriteria").value = searchString;
  3497.     googlebarClearTerms();
  3498.     googlebarAddTerm(searchString);
  3499.     myGooglebarHighlight.delayHighlight();
  3500.     googlebarSearch(event);
  3501. }
  3502.  
  3503. function googlebarDisplaySuggest(searchString, labelArray, resultArray, otherArray)
  3504. {
  3505.     var suggestPop = myGooglebarUtil.getElement("googlebarSuggestMenu");
  3506.     var ndx;
  3507.     var tempNode;
  3508.     
  3509.     // clean up all of the popup menu items
  3510.     for (ndx = suggestPop.childNodes.length - 1; ndx >= 0; ndx--) {
  3511.         suggestPop.removeChild(suggestPop.childNodes[ndx]);
  3512.     }
  3513.     
  3514.     // add suggest items to the popup menu
  3515.     for (ndx = 0; ndx < labelArray.length; ndx++) {
  3516.         tempNode = document.createElement("menuitem");
  3517.         tempNode.setAttribute("label", labelArray[ndx] + " - " + resultArray[ndx]);
  3518.         tempNode.setAttribute("class", "menuitem-all");
  3519.         tempNode.setAttribute("oncommand", "googlebarSearchSuggest(event, '" + labelArray[ndx] + "');");
  3520.         suggestPop.appendChild(tempNode);
  3521.     }
  3522.     
  3523.     suggestPop.showPopup();
  3524. }
  3525.  
  3526. /*
  3527. function googlebarDisplaySuggest(searchString, labelArray, resultArray, otherArray)
  3528. {
  3529.     var display = "";
  3530.     
  3531.     display += " Google Suggest Result for '" + searchString + "'\n";
  3532.     display += "-------------------------------------------------\n";
  3533.  
  3534.     for (var i = 0; i < labelArray.length; i++) {
  3535.         display += labelArray[i];
  3536.         display += "\t\t";
  3537.         display += resultArray[i];
  3538.         display += "\n";
  3539.     }
  3540.     
  3541.     alert(display);
  3542. }
  3543. */